* Allow converter.optional to take a converter such as converter.pipe as its argument
* Only turn optional into a Converter if needed
* Move call to Converter constructor to the end of optional()
The constructor consumes __annotations__, so move the constructor call to after those have been set on the optional_converter function
* Update tests/test_converters.py
* Update tests/test_converters.py
---------
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* allow __suppress_context__ to be mutated on frozen exceptions
* add changelog
* and __notes__! lets' not forget that.
* add notes to news
* add tests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix improt
* fix test
* fix tests again
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Make Converter a kind of adapter, fix converters.pipe
* Fix import cycle on 3.7/8
* stray space
* Create static __call__ on Converter instantiation
* Add tests for adapters doing passing correct args
* Add news fragment
* Restore basic functionality on 3.14[sic]
Essentially switch to PEP 649 / 749 for annotations. Some tests need to
be skipped for now, but the rest is working.
Fixes#1326
* Add news fragment
* We have not 3.14 CI yet
* Use imprerative xfails instead of skips
* Add support for __attrs_init_subclass__
* Fix test docstring
* Fix import
* Add versionadded
* Invert logic and add example
* Explain behavior in API docs
* Move to narrative docs
* Link
* once is enough
* why hide
* endash
* better phrasing
* 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>
* Speed up __eq__
* Changelog, disallow nans in tests
* Fix `eq_key` comparisons
* Rework changlelog
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Make docs more precise
---------
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>
* Preserve AttributeError in slotted classes with cached_property
In slotted classes' generated __getattr__(), we try __getattribute__()
before __getattr__(), if available, and eventually let AttributeError
propagate. This matches better with the behaviour described in Python's
documentation "Customizing attribute access":
https://docs.python.org/3/reference/datamodel.html#customizing-attribute-access
Fix https://github.com/python-attrs/attrs/issues/1230
* Update changelog.d/1253.change.md
---------
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Fix test_ne in test_cmp.py for Python 3.13
Compiler in Python 3.13+ strips indents from docstrings
so they need to be compared without it for new Pythons.
Fixes: https://github.com/python-attrs/attrs/issues/1228
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
assoc() no longer raises a deprecation warning since commit
22ae8473fb but the 'with
pytest.deprecated_call():' in that test was not removed then (in
contrast with other test cases).
Maybe this got unnoticed due to a pytest bug?
In any case, using pytest 8+ (and keeping deprecated_call()) shows that
no warning is raised and the test fails.
Removing the upper bound on pytest in dev dependencies as tests now
pass with pytest 8.0.
Fix#1233.
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Remove undesirable original class reference when using slotted cached_property
* Update closure cells for slotted cached property functions
* Changelog
* fixup py 3.7 test
* Add support for cached_properties to slotted attrs classes.
* Remove locking from implementation
* Add test for multiple cached properties and fix bug
* Add changelog file
* Document slotted cached properties
* Add cached_property hypothesis check.
* Only run cached_property imports on python 3.8+
* Use cached _obj_setattr instead of `object.__setattr__`
* Correctly resolve mro for __getattr__ in cached properties
* Use _get_annotations rather than branching on class dict entry
* Optimise __getattr__ code by front loading branching, and injecting locasl variables
* Remove unnecessary `__attrs_original_getattr__` from class dictionary.
---------
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Remove work-arounds for setting cell_contents
Simple assignment to cell_contents works starting from Python 3.7[1].
This is also the minimum supported version of Python according to
pyproject.toml. It follows that we don't need complex work-arounds that
were needed in the past.
Also tested on pypy 3.8.
[1] https://bugs.python.org/issue30486
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
Some error messages changed in mypy 1.7.0 and pyright 1.1.335.
Also, test_mypy sometimes fails with xdist (-n auto). A failure I can
reliably reproduce locally is due to changes in type variables numbering.
There may be other issues.
* Pass args from `__init__` to `__attrs_pre_init__` if requested
Detect if `__attrs_pre_init__` has arguments besides `self`
using `inspect.signature`. If so, pass `__attrs_pre_init__`
the same arguments that `__init__` (or `__attrs_init__`)
expects.
* Add changelog entry for `__attrs_pre_init__` args changes
* Don't use monkeypatch in new code
* Clarify docs
* Missed one monkeypatching
---------
Co-authored-by: Hynek Schlawack <hs@ox.cx>
* Fix TypeError for asdict with namedtuples and retain_collection_types=True
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add news fragment in `changelog.d`
* fix pre-commit interrogate checker
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix flake8 issue
* also fixed `astuple`
* Add `_is_namedtuple` function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix SyntaxError for python 3.7
* use `issubclass(..., tuple)`
* use issubclass(cf, tuple) if case of TypeError
* pragma: no cover
* Get rid of the `# no cover`
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* simplify a bit
* Update tests/test_funcs.py
* Update tests/test_funcs.py
* Update tests/test_funcs.py
* Update tests/test_funcs.py
* Update tests/test_funcs.py
* Update tests/test_funcs.py
* Update tests/test_funcs.py
* Update tests/test_funcs.py
* Update changelog.d/1165.change.md
* Escape patterns
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>