Commit Graph

132 Commits

Author SHA1 Message Date
Hynek Schlawack d23924f765 Add provisional notice 2020-11-05 10:02:41 +01:00
Hynek Schlawack f2dabeae82
Fix exception chaining on PyPy (#712)
* Fix exception chaining on PyPy

Fixes #703

* Add newsfragment

* Blankly exclude PyPy from coverage reporting

* Manually add default no cover marker
2020-11-04 11:02:15 +01:00
Hynek Schlawack 56c73081c5 Add missing collect_by_mro to typing stubs
Fixes #711
2020-11-03 10:10:43 +01:00
Andrei Bodrov bc527b9f29
[RFC] kw_only python 2 backport (#700)
* Added kw_only support for py2

* Docs update

* Added changelog

* Better exception message, moved code to function

* Moved py2-only functions under if PY2:

* Tested fancy error message for unexpected kw-only argument

* Tested fancy error message for unexpected kw-only argument

* Fixed line length

* Added versionchanged

* Updated docs

* Moved functions back under if PY2 - seems codecov doesn't like them in module scope

* Blacked

* Fixed changelog.d

* Removed redundant brackets in test

* Added assertion to the _unpack_kw_only_lines_py2 - hope it will increase code coverage

* List comprehension -> for loop

* lines.extend? I do not like for-loops

* Fix code

* Fixed style/added comment

* Fixed docs (removed python2 mention)

* Fix lint

* Better docstring

* Rewritten docstring and added example code

* Added quotes

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2020-10-19 11:00:00 +02:00
Hynek Schlawack 0e6c74ac17
Treat frozensets like sets in asdict/astuple (#704)
* Treat frozensets like sets in asdict/astuple

Fixes #657

* Add newsfragment
2020-10-19 10:17:25 +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 4f74fbaca3 Prepare 20.2.0 2020-09-05 12:19:07 +02:00
Hynek Schlawack 74605de4cd Elaborate more on #684 2020-09-05 11:36:09 +02:00
Hynek Schlawack ea04c15d7f Drop superfluous word 2020-09-05 11:24:37 +02:00
Hynek Schlawack 060d1efbdd Add newsfragment on state of NG APIs 2020-09-05 11:23:35 +02:00
Hynek Schlawack c45472286a Fix typo 2020-09-05 11:15:26 +02:00
Hynek Schlawack 504eefe91f
NG: make frozen classes comfortably subclassable (#687)
* NG: make frozen classes comfortably subclassable

* Add newsfragment

* This ain't markdown

* Address review
2020-09-05 11:14:54 +02:00
Hynek Schlawack 48755905ee
Don't reset custom __setattr__ in slotted classes (#681)
* Don't reset custom __setattr__ in slotted classes

Fixes #680

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

* Simplify

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

* Be defensive about __bases__

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

* _Classes_ always have a __dict__

* Tighten xfail

* Clarify what need to be reset and when

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

* Reset __attrs_own_setattr__ along with __setattr__

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

* Update src/attr/_make.py

Co-authored-by: Paul Ganssle <paul@ganssle.io>

* Differentiate between own (= attrs) and custom (= user) __setattrs__

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

* We've always used __bases__ in our call to type()

So no reason for being defensive.

* Update tests/test_setattr.py

Co-authored-by: Paul Ganssle <paul@ganssle.io>

Co-authored-by: Paul Ganssle <paul@ganssle.io>
2020-09-05 09:46:06 +02:00
Hynek Schlawack bfd7bb49b4
Ignore inherited field when comparing Attributes (#684)
* Ignore inherited field when comparing Attributes

fixes #682

* add newsfragment
2020-09-03 07:16:58 +02:00
Paul Ganssle dfb2ee284d
Make `zope` a semi-optional test dependency (#685) 2020-09-03 06:56:17 +02:00
Hynek Schlawack 25cc8380ec Add newsfragment for #671 2020-08-23 08:02:20 +02:00
Hynek Schlawack 766a787b50 Add newsframent for #675 2020-08-23 08:01:02 +02:00
Hynek Schlawack 90386b669e Prepare 20.1.0 2020-08-20 19:16:15 +02:00
Hynek Schlawack d523371d80 Prevent reST getting upset by multiple links to #666 2020-08-20 19:11:40 +02: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 aea6d6f551 Announce `import attrs` 2020-08-14 08:18: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 a74c32bcde Relax _ConverterType to work with chained converters
I guess we could add a separate type for chained converters but I don't think
that's worth it.
2020-07-20 12:57:37 +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
Hynek Schlawack 01899794ef
Fix newsfragment typo 2020-05-18 07:20:30 +02:00
Hynek Schlawack 277a5c1d45
Add control to generate __[sg]etstate__ (#642)
* Add control to generate __[sg]etstate__

Pass *getstate_setstate* to attr.s to control the generation.  Mostly
interesting for disabling it in slotted classes.

Fixes #512,#513

* Update glossary.rst
2020-05-11 07:11:24 +02:00
Hynek Schlawack 33b61316f8
Fix attribute collection (#635)
Co-Authored-By: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
2020-04-06 11:41:52 +02:00
Hynek Schlawack 196d948613
Add auto-detection of self-implemented methods (#607)
* Implement auto_detect

Fixes #324

* Add test demonstrating total_ordering

* Ensure the order of applying total_ordering does not matter

* Warn if a method is missing

* Revert "Warn if a method is missing"

This reverts commit 590ef43458040e0a1b9f3644ba22b4229f7d6990.

* Add stern warning that nobody will read
2020-03-16 13:03:12 +01:00
smarie 07810aec7b
Fix issue 589 (#590)
* from parsyfiles development (https://github.com/smarie/python-simple-file-collection-parsing-framework):
* added new 'chain' validator to allow users to chain their custom validators with, for example, 'instance_of'
* added utility methods to get the declared attribute type (by inspecting its validators) and to check if it is optional

* from parsyfiles development (https://github.com/smarie/python-simple-file-collection-parsing-framework):
* added tests
* fixed bug with optional validator to pass tests :)

* from parsyfiles development (https://github.com/smarie/python-simple-file-collection-parsing-framework):
* completed doc api.rst
* small mod in tests

* Fixed issue with empty cell in closure when slots are used. Fixed #589

* Removed api.rst mods erroneously injected from another branch.

* Removed api.rst mods erroneously injected from another branch.

* noqa so that flake8 is happy

* Fixed lint error

* Added towncrier changelog entry

* Attempt to fix linter error

* Update tests/test_slots.py

* Last lint fix

* Update changelog.d/590.change.rst

Co-Authored-By: Hynek Schlawack <hs@ox.cx>

* Added extensive doc in the new test

* Update tests/test_slots.py

* last lint error

Co-authored-by: Sylvain MARIE <sylvain.marie@se.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
2020-03-13 06:06:14 +01:00
Hynek Schlawack 9e14962988 Make changlog more flashy 2020-03-06 13:57:12 +01:00
Simone Robutti 4dea97e633
added first doc stub (#506)
* added first doc stub

* fixed test

* review

* added newsfragment

* improved docs

Co-authored-by: Simone Robutti <simone.robutti@teraki.com>
2020-03-06 13:54:27 +01:00
Nativ Issac 9fcfe3479f Add and_ converter (#618)
* Add and_ converter

* update _make

* Refactored code according to review

* fixed some linting errors

* minor refactor

* fixed CR comments

* fixed CR comment #2

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2020-03-06 10:34:11 +01:00
Paul Ganssle d6a65fb89f
Use a wrapper class for cache hash to prevent cache serialization (#620)
* Use an self-clearing subclass to store hash cache

Rather than attempting to remove the hash cache from the object state on
deserialization or serialization, instead we store the hash cache in an
object that reduces to None, thus clearing itself when pickled or
copied.

This fixes GH #494 and #613.

Co-authored-by: Matt Wozniski <godlygeek@gmail.com>

* Add test for two-argument __reduce__

I couldn't think of any way to make a useful and meaningful class that
has no state and also has no custom __reduce__ method, so I went
minimalist with it.

* Improve test for hash clearing behavior.

Previously, there was some miniscule risk of hash collision, and also it
was relying on the implementation details of `pickle` (the assumption
that `hash()` is never called as part of `pickle.loads`).

* Add improved testing around cache_hash

* Update src/attr/_make.py

Co-Authored-By: Ryan Gabbard <gabbard@isi.edu>

* Update comment in slots_setstate

Since the cached hash value is not actually serialized in __getstate__,
__setstate__ is not actually "clearing" it on deserialization - it's
initializing the value to None.

* Add changelog entry

* Remove changelog for #611

This change was overshadowed by a more fundamental change in #620.

Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
Co-authored-by: Ryan Gabbard <gabbard@isi.edu>
2020-02-10 17:16:07 +01:00
Paul Ganssle 9b5e988ccc Fixed frozen and cache_hash incompatibility (#612)
* Add xfailing test for frozen/cache_hash issue

This is a failing test for GH issue #611, with the xfail decorator to be
removed when the issue is fixed.

* Fix incompatibility between frozen and cache_hash

Fixes GH issue #611: serialization of a class with frozen=True and
cache_hash=True will now succeed rather than raising a
FrozenInstanceError.

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2020-01-13 08:46:11 +01:00
Hynek Schlawack 495968281c
Officially drop Python 3.4 (#608) 2020-01-06 12:32:28 +01:00
Hynek Schlawack 38d21a7ce6 Remove unnecessary newsfragment 2019-11-18 08:54:43 +01:00
Tim Gates ee44563094 Fix simple typo: developement -> development (#600)
* Fix simple typo: developement -> development

* Add towncrier file

* Fix PR number
2019-11-18 08:54:17 +01:00
Hynek Schlawack 823c1c332c Prepare 19.3.0 2019-10-15 07:46:04 +02:00
Bruno Oliveira e2b02ec39e Fix default values that are not comparable with '==' (#586)
Fix #585
2019-10-15 06:56:12 +02:00
Hynek Schlawack c0eda39363 Start 19.3 cycle 2019-10-01 17:13:44 +02:00
Hynek Schlawack 9e15786967 Merge branch 'version-info' 2019-10-01 16:25:50 +02:00
Hynek Schlawack 528323040f Prepare 19.2.0 2019-10-01 16:21:36 +02:00
Hynek Schlawack 955d622493
Add attr.__version_info__ (#580)
* Add attr.__version_info__

This allows users to check for features and avoid deprecation warnings without
breaking backward compatibility.

* Add newsfragment

* Stay ASCII

* Typo

* Add stubs for _version.py

* Address David's feedback

* Handle PY2 better in comparability test

* drop the ing
2019-10-01 16:06:36 +02:00
Hynek Schlawack fb5728a357 Add newsfragment 2019-09-26 06:50:04 +02:00
Hynek Schlawack d381f49fc2 We don't have bugfix newsfragments 2019-09-25 16:21:56 +02:00
Hynek Schlawack 08fcfe91d4
Split cmp into eq and order (#574)
* Split cmp into eq and order

Fixes #170

* Fix tests on old pypy3 versions

Old as in: currently on AP.

* Fix issue number and clarify newsfragment

* Clarify behavior and interaction between cmp/eq/order

* This sounds better

* Address Julian's review comments

* Missed a cmp

* Test the behavior of Attribute.cmp

* Make test more idiomatic

* Explain assumptions

* Clarify comment

* Grammar

* One more cmp!
2019-09-22 15:07:19 +02:00
Hynek Schlawack ef488122eb Add more verbose explanation for matches_re 2019-09-09 10:50:31 +02:00