Commit Graph

129 Commits

Author SHA1 Message Date
Hynek Schlawack 42c954869d
Invert API docs to point from NG to OG (#1316)
* 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
2024-08-02 08:03:14 +02:00
Hynek Schlawack f5683b852b
converters: allow wrapping and passing self and fields (#1267)
* 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>
2024-07-28 13:55:24 +00:00
Libor Martínek 7c9b31ea7b
Add `attrs.validators.or_` validator (#1303)
* 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>
2024-07-17 12:01:41 +00:00
Hynek Schlawack 9e803dd683
to_bool: avoid creating sets on each call 2024-03-17 09:04:54 +01:00
Hynek Schlawack 9cf3d338f4
Improve/harmonize docstrings 2024-03-17 08:07:39 +01:00
Hynek Schlawack 8460190b29
Remove attrs.validators.provides (#1265)
* Remove attrs.validators.provides

* Add news fragment
2024-03-16 21:15:47 +00:00
Hynek Schlawack f590f44cfd
docs: style improvements 2024-03-16 16:22:58 +01:00
richardsheridan f070a21a3e
correct reference in Setters section of api.rst (#1224) 2024-01-12 08:38:07 +00:00
Hynek Schlawack 0d1be891df
Build docs on 3.12 2023-11-28 13:26:27 +01:00
Hynek Schlawack c02d993f9d
Fix object index in API docs by splitting API docs in two (#1080)
* 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
2023-01-10 17:53:28 +01:00
Hynek Schlawack 906b732e23
Re-add attr and attrs ..module
But add it where it belongs: API

Fixes #1073
2023-01-02 16:27:37 +01:00
Hynek Schlawack 98aa688501
Clarify make_class argument type (#1075) 2023-01-02 08:50:57 +01:00
Hynek Schlawack 6957e4a356
Use new typographic branding in the last rst file, too 2022-12-20 10:17:48 +01:00
Hynek Schlawack a760574795
Convert init.rst to md 2022-12-20 08:22:51 +01:00
Hynek Schlawack 0f6a9b4753
Add unsafe_hash alias for class-wide hash (#1065)
* 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
2022-12-02 07:45:13 +01:00
Alex Ford ee3ecb112f
Add Attribute.alias (#950)
* 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>
2022-11-30 14:39:57 +00:00
Nick Timkovich f870beb84a
Add a not_ validator (#1010) 2022-09-04 13:55:02 +02:00
Kevin M Granger c860e9dd25
Use enum for typing NOTHING (#983)
* 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>
2022-08-27 17:41:56 +02:00
Hynek Schlawack 08f8319efe
Drop Python 3.5 (#988)
* 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
2022-08-05 09:48:00 +02:00
Hynek Schlawack 696fd78690 Hyphenate compound adjectives 2022-07-28 09:23:44 +02:00
Hynek Schlawack a7e82b5c41 Polish docs around #951 2022-06-13 08:33:23 +02:00
Matthieu Melot f008d86a8e
Typo fix (#957)
Should read top-level, not to-level.
2022-05-06 18:09:28 +00:00
wouter bolsterlee a22e98c6cb
No longer explicitly subclass ‘object’ (#940)
This is no longer relevant in Python 3+. Follow-up to !936.

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2022-03-21 10:35:44 +01:00
NI1993 7804a68ee3
Added attrs.validators.min_len() (#916)
* 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>
2022-02-02 09:10:33 +00:00
Hynek Schlawack d6f9b5a967 Inline NO_OP API docs
Sphinx's autodata changed behavior and started adding the docstring of
`object`.

Fixes #917
2022-02-02 08:22:45 +01:00
Hynek Schlawack e188af7bc4 Fix copy-pasted line in docs
Ref https://github.com/python-attrs/attrs/pull/887#discussion_r789198858
2022-01-21 07:22:58 +01:00
hkclark 7695908aa7
docs: fix very minor typo (#894)
Co-authored-by: kclark <kclark@autoverify.net>
2021-12-29 07:42:51 +01:00
Hynek Schlawack 4278b2df39 Final light polish on docs 2021-12-27 09:21:11 +01:00
Hynek Schlawack e7345584ff
Add attrs namespace (#887) 2021-12-25 15:15:10 +01:00
Hynek Schlawack 679e4b443d
NG: convert on setattr by default (#886)
* 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
2021-12-14 15:50:37 +01:00
Hynek Schlawack 29447f81af
Document the various core names and why they exist (#871)
* 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
2021-11-24 09:39:41 +01:00
Stefan Scherfke c6143d518b
Add "no_run_validators()" context manager (#859)
* Add "no_run_validators()" context manager

* Move functions to validators module

* Update changelog entry

* Add a few docstring improvements and fixes

* Update tests/test_validators.py

* Minor polish

Signed-off-by: Hynek Schlawack <hs@ox.cx>

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2021-11-17 07:05:01 +01:00
Kyle Altendorf 68be706621
Avoid attr.attr.frozen and attr.attr.mutable in Sphinx object inventory (#851)
https://github.com/altendky/qtrio/issues/269
2021-10-12 07:42:46 +02:00
Hynek Schlawack 124c20cde0
Document Attribute.eq_key & .order_key (#847)
* Document Attribute.eq_key & .order_key

Fixes #839

Signed-off-by: Hynek Schlawack <hs@ox.cx>

* Add for example
2021-10-06 12:21:36 +02:00
Stefan Scherfke 52fcad29bb
Add additonal validators (#845)
* Add additonal validators

* Python 2 \o/

* Add changelog entry

* Add "versionadded" tags

* More python 2

* Add doctests and rename maxlen to max_len

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2021-09-24 12:47:19 +02:00
Rebecca Turner e84b57ea68
Inline distutils.util.strtobool in tests (closes #813) (#830)
* 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>
2021-08-10 07:45:28 +02:00
Karthikeyan Singaravelan 8613af97bb
Add __match_args__ to support match case destructuring in Python 3.10 (#815)
* Add support to generate __match_args__ for Python 3.10.

* Add versionadded directive.

* Update stubs.

* Update changelog and add a test to typing examples.

* Fix error regarding new-style classes in Python 2.

* Fix lint error regarding line length.

* Fix lint error regarding trailing whitespace.

* Add docstrings for interrogate.

* Use _has_own_attribute instead of cls.__dict__ contains check.

* Update docs as per review comments.

* Revert mistaken changelog update.

* Add Python 3.10 pattern matching syntax test cases.

* Update define signature with match_args.

* Fix conftest formatting.

* Fix isort formatting.

* Bump to Python 3.10 to parse syntax.

* Bump basepython of lint to Python 3.10 for parsing.

* Move lint to py310

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2021-05-18 07:02:06 +02:00
Hynek Schlawack 743f973889
Add narrative docs for #787 (#801) 2021-05-04 17:41:14 +02:00
Hynek Schlawack f47e568c9e
Make NG APIs official (#786) 2021-04-09 20:36:10 +02:00
Antonio Botelho f580185cc4
Undeprecate cmp (#773)
* Document comparison

* Grammar

* Stress independence of eq/order

* Add example for eq

* Be consistent with fields

* Undeprecated cmp

* Update doc to remove cmp deprecation

* Reintroduced deprecation warning on Attribute cmp property

* Added changelog file

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2021-02-28 13:20:40 +01:00
Antonio Botelho aefdb117fa
Allow user to customize how an attribute is compared (#435) (#627)
* Updated implementation of comparison behaviour customization.

* Fixed version of next release, updates newsfragment and documentation.

* Fixed documentation.

* Fixed documentation.

* Fixed comments and changelog.

* Fix doctest error

* Update src/attr/_make.py

Co-authored-by: Hynek Schlawack <hs@ox.cx>

* Pass eq_key and order_key explicitly in _CountingAttr

* Merged with master and resolved conflics after introduction of _make_method

Co-authored-by: Antonio Botelho <antonio@inhames.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
2021-02-22 08:48:34 +01:00
Hynek Schlawack ae51f34681 Attribute.assoc → evolve 2020-10-17 07:27:36 +02:00
Stefan Scherfke 0eae613ce1
Add hooks for field transformation and for asdict serialization (#653) 2020-10-15 09:33:59 +02:00
Hynek Schlawack 6aca10f2a7 Beef up glossary and urge people more to read it
Ref #691
2020-09-28 11:27:37 +01:00
Hynek Schlawack fda437c91f
Add attr.field (#669)
* Add attr.field

* Add newsfragment

* better wordzzz

* Typo and clarification
2020-08-20 19:01:34 +02:00
Hynek Schlawack b02335f59d
Add attr.define/mutable/frozen (#666)
* 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
2020-08-17 16:22:33 +02:00
Hynek Schlawack 3aa497d02b
Move resolve_types to _funcs and tweak docs
Signed-off-by: Hynek Schlawack <hs@ox.cx>
2020-07-22 12:19:58 +02:00
David Euresti c42bf9ebb9
Add attr.resolve_types (#302)
* 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>
2020-07-22 11:43:07 +02:00
Hynek Schlawack 05e930c36f
Rename converters.chain to converters.pipe
Consistent with setters.pipe and conveys better that it acts like a UNIX pipe.

Signed-off-by: Hynek Schlawack <hs@ox.cx>
2020-07-21 14:43:09 +02:00
Hynek Schlawack 2f6fd8516c
Add on_setattr hooks to attr.s and attr.ib (#660)
* 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
2020-07-20 12:43:10 +02:00