* Add literal string support to includer and exclude filters
* Add docs and changelog for new feature
* Fix typo in `typing_example`
* Add a note to document typo issues while using literal name strings as filter args
* Add more docs
* Add code mark for `AttributeError`
* Fix grammar error and upgrade `versionchanged` info
* Improve docs and examples from
hynek's comments
* Keep example cases the same
* More examples
* Apply suggestions from code review
Co-authored-by: chrysle <fritzihab@posteo.de>
---------
Co-authored-by: Hynek Schlawack <hs@ox.cx>
Co-authored-by: chrysle <fritzihab@posteo.de>
* Raise a deprecation warning when evolve receives insta as a kw arg
Fixes#1109
* Add news fragment
* Raise a better error
* Handle too many pos args
* Lazy import
* Trim traceback
* Add test evolving a field named inst
* Spelling
* Spin positively
* Added `type` parameter to `attrs.field` and test
* Added notice in examples.md
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Added changelog entry
* Fixed docs
* Apply suggestions from code review
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* compat: move check for closure cellvar update wrapper function
This sanity checking code ended up getting decoupled from the old
implementation in a18b3957d5 when a new,
much simpler method was added. This check can fail spuriously in
certain environments where it doesn't even need to be run because the
newer approach is used.
This is noticeable when using python scripts compiled by nuitka. Since
next-gen attrs uses slots on everything by default, the use of this
fixup function is now pervasive, as well.
* changelog: note fix
* Semantic newlines
---------
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Remove unnecessary parameterization of tests
* Fix backward compatibility with pickles before v22.2.0
Unfortunately we're using `django-redis` to cache some `attrs` instances
and the change to make `__getstate__` and `__setstate__` use `dict`
values instead of `tuple` values prevents reading any values from the
cache when updating to `attrs>=22.2.0`. We get an `AttributeError`
raised for all attributes.
This happens because the tuple of values stored in the original pickle
is checked for the name of the attribute and so none of the attributes
are set on unpickle.
To address this I've made a change so that `__setstate__` will still be
able to handle values pickled as `tuple`s allowing existing pickles to
be unpickled.
The test just contains a pre-pickled value due to the complexities
around tying to mock methods on a slotted as documented[^1].
I realise that documentation also mentions that we should "think twice"
before using pickle, but sometimes those decisions predate our
involvement in a project! In addition, pretty much all of Django's cache
implementations are built around using pickle by default. This change
will allow an easier path to upgrade by unpickling and repickling all
values in the cache.
Regression in 89a890a326.
[^1]: https://www.attrs.org/en/latest/glossary.html#term-slotted-classes
* Update 1085.change.md
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Add AttrsInstance protocol to forgotten attrs.asdict and attrs.astuple
* Add mypy test for attrs.asdict
* Add changelog entry for attrs.asdict
* Clarify it's about type stubs
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Switch changelog to markdown
* Add changelog except back to long description
* Fix MANIFEST.in
* Re-add towncrier draft entries
* Write the title outselves
* Add warning box
* Make changelog format more KeepAChangelog-ish
* Link latest changes to main tree
* Move link into warning
* KAC has no empty lines between entries
* There's no more .rst in the root dir
* Add unsafe_hash alias for class-wide hash
Fixes#1003
* Add news fragment
* Add type hints / type examples
* Complete attr.s's api string in api.rst
* Address feedback
* Clarify
* Shuffle around
* Spike `alias` implementation.
* Move default alias init to after field_transformer.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fixup docs.
* Update docs/extending.rst
* Pre-commit fixes
* Partially fix doctest
* Add test docstrings.
* Add typing_example tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Tidy typing_example
* Add note in init.rst on private aliases
* Add alias example to examples.rst
* Assert to comment
* Add changelog entry
* Fixup doc error
* Tidy dataclass_transform docs
* Lil' spice for the changelog.
* Fix doctest
* Update extending.rst
* Make alias introspection more explicit
* Update src/attr/_make.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Use enum for typing NOTHING.
This will allow those extending attrs
to type NOTHING as Literal[NOTHING].
* Make test_dunders test `NOTHING` directly
* Reflect NOTHING enum typing in __init__.pyi
* Fix docs for NOTHING
* Add changelog entry
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: Hynek Schlawack <hs@ox.cx>
Co-authored-by: Tin Tvrtković <tinchester@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Drop Python 3.5
Less than 0.5% of our downloads are 3.5 and it allows us to simplify A LOT of code.
Fixes#965
Signed-off-by: Hynek Schlawack <hs@ox.cx>
* Run 3.6 under coverage
* Add newsfragment
* Probably don't need 3.7 for coverage
* Everything is ordered!
* pre-commit autoupdate, add yesqa
The docstring of _in() says the ValueError would contain these, however
it didn't. Adding said arguments enables uniform processing of
ValueErrors raised by validators. One might for example want to extract
the attr.name and the value that raised the error to show a custom, more
user-friendly error message.
* Drop the deprecated Attribute.cmp
This has nothing to do with the cmp argument to attr.s/define which have been
undeprecated.
* Add newsfragment
* Add test for attr.ib(cmp=)
* Drop Python 2.7
The tooling situation around Python 2 has deteriorate to such a degree that
upholding compatibility is not tenable anymore for a volunteer-run project.
Signed-off-by: Hynek Schlawack <hs@ox.cx>
* Add newsfragment
* Run Python 3.5 under coverage to make up for Python 2.7
* Wait for py35 in parallel
* Remove fullmatch kludge
* Remove Python 2-specific code
* Revert empty slot test
Also disable pyupgrade on that file.
Signed-off-by: Hynek Schlawack <hs@ox.cx>
* We DO run under 3.5
* Remove __qualname__ workarounds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update changelog.d/936.breaking.rst
Co-authored-by: Tin Tvrtković <tinchester@gmail.com>
* Compare methods using is
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tin Tvrtković <tinchester@gmail.com>
* Add Multiple Validators to deep iterable
* Add Tests + Fix some doc strings
* Update typing
* Limit this PR to only accepting a list of member validators
* Respond to PR comments
* Commit missing file
* Apply suggestions from code review
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Split other test too
* Fix CI + Remove Weird parens
* Use and_ instead of And_
* Add tuple to list of tests
Co-authored-by: Hynek Schlawack <hs@ox.cx>