* Add disclaimer to attr NS
* Transplant API docs from attr.s to attrs.define
* Transplant API docs from attr.ib to attrs.field
* Remove stale references to attr.ib
* Fix refs
* Link to glossary
* Explain why
* Links from API docs, too
* Link type annotations for good measure
* converters: allow wrapping & takes_self
* Add takes field
* Add news fragment
* Refactor name and call creation
* Make argument names more idiomatic
* Add missing hints
* Make 3-arg converters zero-overhead at runtime
* Remove unnecessary changes
* More idiomatic name
* Explain method
* Make pickle test more meaningful
* Add unit tests for fmt_converter_call
* Check our eq works too
* Convert Converter docstring to Napoleon
* Fix rebase fubar
* Add ~types~
* Comment out failing mypy tests for now
* Fix mypy tests
* Add warning
* Add narrative docs
* Fix converter overloads, add tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: Tin Tvrtković <tinchester@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Implement attrs.validators.or_ validator
* Add tests/test_validators.py::TestOr test cases
* Add test for _OrValidator.__repr__ method
* Add description of attrs.validators.or_ to docs/api.rst
* Add changelog entry
* Swap double quotes for single because doctests don't like it
* Rename changelog fragment pointing to incorrect number
* Silence ruff linter warnings
Although good warning in general, in this particular code, they
do not fit here.
* BLE001 Do not catch blind exception: `Exception`
`validators` usually raise `ValueError` upon their violation.
However, it's not the only `Exception` they can raise - cf.
`attrs.validators.not_` - therefore, it is desirable to catch
them all!
* PERF203 `try`-`except` within a loop incurs performance overhead
Fair point, but the loop is written in a way to short-circuit,
ie. it will finish when a first validator is satisfied.
* S112 `try`-`except`-`continue` detected, consider logging the exception
Not applicable here, we care only if **all** validators raise
an exception, which is already accomodated for after the `for`
loop.
* Apply suggestions from code review
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Rework example of or_ validator in api/docs.rst
* Update docs/api.rst
---------
Co-authored-by: Hynek Schlawack <hs@ox.cx>
Co-authored-by: Libor <libas.martinek@protonmail.com>
* Fix object index in API docs
* Refactor API docs, prefer new namespace in examples
* Missed one
* Technically optional, practically confusing
* Simplify / clarify intro to API
* No need to make this clickable
* 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
* Added attrs.validators.min_len()
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Rename foo.change.rst to 916.change.rst
* Update src/attr/validators.py
Co-authored-by: nativ <nativi@spotnix.io>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* NG: convert on setattr by default
Not doing that from the get-go was an oversight.
Fixes#835
* Add optimization for default on_setattr w/ no work to do
Otherwise we'd end up with an explicit setattr every time.
* Fix optimization for NG default & j/ convert
* NG is actually 3.6+
* Add test for convert optimization for good measure
* Document the various core names and why they exist
Signed-off-by: Hynek Schlawack <hs@ox.cx>
* Remove stray backtick
* Add example of new API
* Link PEP 526
* future is now
* phrase and typos
* typo/grammar
* typo
* Better phrasing
* Add missing and
* less words = better
* polish
* phrasing
* looks weird but is correct
* comma spliiiiceeeee
* example
* make it sound less dry
* fix
* phrasing
* Inline distutils.util.strtobool in tests (#813)
`distutils` is deprecated in Python 3.10 and slated for removal in
Python 3.12. Fortunately, `attrs` only uses `distutils` once and it's
trivial to remove.
As suggested by @sscherfke, add the `to_bool` converter to
`converters.py`.
Closes#813
Co-authored-by: Stefan Scherfke <stefan@sofa-rockers.org>
* Use :raises: directive in docstring
* Remove f-strings for Py2.7 and 3.5 support
* Add to_bool tests
Co-authored-by: Stefan Scherfke <stefan@sofa-rockers.org>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Add attr.auto/mutable/frozen
Prepare for import attrs y'all!
Signed-off-by: Hynek Schlawack <hs@ox.cx>
* Try combining coverage using 3.8, always
* Add tests for overriding of auto_attribs
* Clarifications
* Add newsfragment
* s/auto/define
This is going be the next-gen name anyways, so no need to introduce new names.
Signed-off-by: Hynek Schlawack <hs@ox.cx>
* Missed two
* Add type stubs
* Beg for patience
* Explain second setup-python action
* fix comment
* Add attr.resolve_types
This adds `attr.resolve_types` which can be used to resolve forward declarations in classes created using `__annotations__`
Fixes#265
* Fix flake8 and doctest
* Missed one
* Fix lint
* Address CR comments
Add to stubs
Make it a decorator, because why not?
* Fix test
* Rerun-tests please
* Rerun-tests please
* Fix another
* Fix lint
Co-authored-by: David Euresti <david@zapgram.com>
* Add on_setattr hooks to attr.s and attr.ib
Signed-off-by: Hynek Schlawack <hs@ox.cx>
* Add PR newsfragment
* Fix attr.s doc sig
* Make _DisableType private
* Mark setters.frozen as NoReturn
* Rename setters.DISABLE to setters.NO_OP to clarify its purpose
DISABLE sounds less purposeful and doesn't convey its meaning as well.
* Fix type
* Loosen up type for convert even further
* Tighten type a tiny bit