Commit Graph

245 Commits

Author SHA1 Message Date
Hynek Schlawack ecdb117407
Fix type annotation for resolve_types() (#1141) 2023-06-04 11:27:09 +02:00
Hynek Schlawack 747b9ded2f
Simplify CI and use .python-version (#1140)
* Simplify CI and use .python-version

* Test CI on pypy 3.9 too

* We don't need .gitignore to keep the dir anymore
2023-06-04 07:33:48 +02:00
Hynek Schlawack 1e2f6f9cac
Prepare 23.1.0 2023-04-16 12:22:15 +02:00
Hynek Schlawack a7e1a56da6
Fix missing backtick 2023-04-16 12:17:35 +02:00
Lanqing Huang c4c6fdd658
Add literal string support to include and exclude filters (#1068)
* 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>
2023-04-14 08:54:31 +00:00
Hynek Schlawack c8b342d34f
Deprecate zope-interface support (#1120) 2023-04-10 15:34:38 +02:00
Hynek Schlawack 7d55876ed3
Accept tuples in attrs.validators.optional (#1122)
* Accept tuples in attrs.validators.optional

Fixes #937

* Add news fragment
2023-04-10 09:49:51 +02:00
Hynek Schlawack a14e1859b8
Raise a deprecation warning when evolve receives insta as a kw arg (#1117)
* 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
2023-04-05 08:33:02 +02:00
chrysle f04fa4ed8e
CONTRIBUTING: Added instructions for PR workflow (#1105)
* CONTRIBUTING: Added instructions for PR workflow

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added changelog entry

* Use inline code for changelog filename

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>

* Add console prompt to command

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>

* Made some more improvements

* Apply suggestions from code review

* Update .github/CONTRIBUTING.md

* Update changelog.d/1105.change.md

* Update .github/CONTRIBUTING.md

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>

* Update .github/CONTRIBUTING.md

* Update .github/CONTRIBUTING.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
2023-04-03 16:34:43 +00:00
chrysle 65ee286d6a
Added `type` parameter to `attrs.field()` function (#1107)
* 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>
2023-04-03 14:40:45 +00:00
Tin Tvrtković c7308a66ef
Flesh out resolve_types (#1099)
* Flesh out resolve_types

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add changelog entry

* Fix flake?

* Update 1099.change.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
2023-03-18 19:31:15 +01:00
T b950cb8d83
compat: move check for closure cellvar update wrapper function (#1092)
* 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>
2023-02-27 07:07:34 +07:00
Hynek Schlawack 99925dbc2e
Add news fragment for #993 2023-02-06 09:40:43 +01:00
Hynek Schlawack 415147c176
Add news fragment for #1079 2023-02-06 09:36:10 +01:00
Nick Pope c9150d278c
Fix backward compatibility with pickles before v22.2.0 (#1085)
* 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>
2023-01-25 06:58:31 +00:00
Vyacheslav Tverskoy 882805e173
Add AttrsInstance protocol to forgotten attrs.asdict and attrs.astuple (#1090)
* 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>
2023-01-23 09:21:20 +00:00
Bryan Forbes 46053d703d
Fix @frozen typing to work on PEP-681 checkers (#1084) 2023-01-12 07:22:13 +01:00
Julian Berman a71fbbad89
Fix @frozen exceptions to allow __traceback__ to be set. (#1081) 2023-01-08 18:34:28 +01:00
Hynek Schlawack a9960de98d
Prepare 22.2.0 2022-12-21 10:07:30 +01:00
Hynek Schlawack afe211143d
Switch changelog to markdown (#1067)
* 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
2022-12-07 09:15:46 +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
Hynek Schlawack 67dc8cc261
Improve news fragments 2022-12-01 17:00:20 +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
Hynek Schlawack c20a9dc7b9
Add defaults to cmp_using stubs (#1027)
Fixes #1026
2022-09-19 09:20:55 +02:00
Hynek Schlawack c3078e33d0
Unpin towncrier 2022-09-12 15:18:41 +02:00
Nick Timkovich f870beb84a
Add a not_ validator (#1010) 2022-09-04 13:55:02 +02:00
layday f7fa5a810c
Fix type errors in Pyright (#999) 2022-08-30 15:06:10 +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 fab5a9289d
Deprecate Python 3.6 (#1017)
* Rename CI workflow to a more meaningful name

* News fragment
2022-08-22 16:43:28 +02:00
Hynek Schlawack cd35505960
Fix typo 2022-08-22 16:39:08 +02:00
Hynek Schlawack 19f41dda6f
Add news fragement for #1009 2022-08-18 09:01:32 +02:00
Hynek Schlawack 70b7f885f4
Add newsfragment for #997 2022-08-16 07:26:50 +02:00
Hynek Schlawack c58ffd4e4c
Call abc.update_abstractmethods on 3.10+ (#1001) 2022-08-11 11:33:34 +00:00
Hynek Schlawack 351637400a
Polish newsfragments 2022-08-10 15:03:57 +02:00
Hynek Schlawack 4a281b04b4
Add warning re #993 2022-08-10 14:32:00 +02:00
Hynek Schlawack 6151683244
Eliminate most str.format() and %-formatting (#995)
* Eliminate most str.format() and %-formatting

* Add newsfragment
2022-08-10 12:41:46 +02:00
davfsa a8191556c0
Speedup `_setattr` usage and fix slight performance regressions (#991)
* Speedup `_setattr` usage and fix performance regressions

* Add changelog file

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2022-08-07 07:52:28 +00:00
Hynek Schlawack 983c2c4293
Re-import AttrsInstance in attrs ns (#994) 2022-08-07 02:13:02 +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 b3dfebe2e1 Prepare 22.1.0 2022-07-28 15:03:02 +02:00
Hynek Schlawack bcef030781 Add newsfragment for #969 2022-07-27 16:37:26 +02:00
Hynek Schlawack 4e6ec65460 Polish changelog entries 2022-07-27 16:14:35 +02:00
Hynek Schlawack a7e82b5c41 Polish docs around #951 2022-06-13 08:33:23 +02:00
iron3oxide 2257a0c60c
Complete error signature of _InValidator (#951)
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.
2022-06-13 07:57:47 +02:00
Hynek Schlawack 738ee63903
Add missing cmp_using to stub files (#949)
* Add missing cmp_using to stub files

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

* Add newsfragment
2022-04-07 07:29:24 +02:00
Hynek Schlawack 0f08b84f3f Unpin towncrier & update template 2022-04-07 07:25:20 +02:00
Hynek Schlawack 155b58418c Add missing newsfragment for #931 2022-04-07 07:13:49 +02:00
Hynek Schlawack c422bf8041
Drop the deprecated Attribute.cmp (#939)
* 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=)
2022-03-21 10:29:58 +01:00
Hynek Schlawack 980c8b04f5
Drop Python 2.7 (#936)
* 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>
2022-03-21 08:47:47 +01:00
Vedant Puri d0c73d8faa
Allow `deep_iterable` member validator to accept a list of validators (#925)
* 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>
2022-03-20 09:48:55 +01:00