Commit Graph

270 Commits

Author SHA1 Message Date
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
Kurt Rose 08b15877c7 Add matches_re validator (#552)
* matches

* added flags pass-through, and multiple function options; defaults to fullmatch

* move logic from validate to constructor

* cleaned up default args / fullmatch emulation

* fixed meta validator

* cleaned up default args / fullmatch emulation

* test cleanup

* versionadded tag

* added changelog entry

* cleaned up type checks, added to api docs and pyi type signature

* black formats

* black formatting

* 100% test coverage

* added example usage of matches_re to docs

* fixing py2 swallow type error and wrong quote in doctest

* explicit tests for all possible func args

* pragma no branch to get coverage 100%
2019-09-09 10:48:52 +02:00
Hynek Schlawack f84f451557
Stop comparing/ordering subclasses (#570)
* Stop comparing/ordering subclasses

This has been deprecated for a year and was raising a warning.

* Kill double consider
2019-09-07 12:19:10 +02:00
wouter bolsterlee 0b913645c5 support custom repr() callable for attributes (#568)
* wip: support custom repr() callable for attributes

see #567

* extend ‘repr=...’ arg type in .pyi stubs

* expand docstring for attr.ib()

* add changelog entry

* add docs with example

* improve my copy/paste skills 🙈

* fix grammar

* fix typo in changelog entry

* fix and improve attrib() docstring

* detect custom repr() once, not per call. be strict about bool.

* use rst syntax, not markdown

* apply hynek's suggestions for changelog entry

* add ‘versionchanged’ note in docstring

* add custom attribute repr= to typing example

* simplify comment
2019-09-06 14:26:08 +02:00
Hynek Schlawack b091f3bf29 fix newsfragment 2019-08-21 12:43:30 +02:00
Hynek Schlawack 22b8cb1c4c Add newsfragment for #559, some polish 2019-08-21 10:28:31 +02:00
Hynek Schlawack bde0801987
Make auto_exc=True classes hashable by ID (#563)
* Make auto_exc=True classes hashable by ID

They now behave as the docs claim.

Fixes #543

* Add PR newsfragment

* Be more specific about NOP
2019-08-19 20:03:44 +02:00
Hynek Schlawack 8174b03b96 Fix stub newline 2019-08-18 08:44:41 +02:00
David Euresti eda9f2de6f Make unique_filename not depend on repr. (#560)
* Make unique_filename not depend on repr.

For debugging purposes, when a method is created it needs to be put
into a "filename".  This filename was generated using `repr(attrs)`
however this meant that the filename could change every time the
program was loaded depending on the whims of repr.  (In particular
free functions and lambdas would include ids)

This solves the problem by changing the name to be <attrs generated
{method} {module}.{qualname}> If it should happen that the name is
taken then -2 will be appended and incremented until a free filename
is found.

* Add tests

* Fix tests and changelog
2019-08-01 12:42:13 +02:00
Hynek Schlawack dc1b5a01e9 Ensure that bare attributes with default None are removed too (#556)
Fixes #523
2019-07-23 13:19:10 +02:00
William Jamir Silva 68af33ec05 Improve the error message informing the value that it got it (#536)
* Improve error message of iscallable validator

* Add stubs for NotCallableError

* Add changelog for iscallable validator
2019-07-20 11:55:26 +02:00
Michał Masłowski 45adbb9fbb Fix deep_iterable, deep_mapping validator type stubs (#533)
Use bound type variables for iterables and mappings of the validated item types, so mypy does not erroneously require both the iterable attribute validated by deep_iterable and the item type validated by the first argument of deep_iterable to have the same type. This fixes #531.
2019-05-27 07:28:27 -07:00
Joshua Oreman 0acfba66f4 Pure-Python approach to closure cell rewriting (#522)
* Pure-Python approach to closure cell rewriting

* Re-add mistakenly removed @skipif(PYPY)

* no-cover the 'should be impossible' lines and the functions that are only defined for their side effects on closure cells
2019-05-08 12:16:02 -04:00
Matt Bullock 957b1982d0 Fix validators __all__ (#517)
* add new validators from #425 to validators.__all__

* add test for each validator, verifying that it is in validators.__all__

* add changelog entry for #517

* apply autolinting

* Make module path absolute
2019-03-13 14:37:49 +01:00
R. Alex Matevish c2a9dd8e11 Remove code and tests related to deprecated 'convert' kwarg (#504)
* Remove code and tests related to deprecated 'convert' kwarg

* Updated documentation, added changelog.d entry

* Fix attrib signature in docstring

* Update docstring version number for removal of 'convert' kw argument in attrib
2019-03-07 09:04:36 +01:00
Hynek Schlawack 0356f0603e Prepare 19.1.0 2019-03-03 09:31:44 +01:00
Hynek Schlawack 0f453c6f88 Add a pointless line to newsfragment to trick towncrier
Otherwise we get invalid RST.
2019-03-03 09:22:38 +01:00
Hynek Schlawack 25a98cbfe5
Implement first class exception support (#500)
* Implement first class exception support

Fixes #368

* Ensure single-attrib classes work too

cf https://github.com/python-attrs/attrs/pull/500#pullrequestreview-201913569

* Call into BaseException to initialiaze self.args

* Leave __str__ alone since we upcall

Based on Python pizza hallway feedback by @ambv.

* remove stray stage

* nope
2019-02-25 18:51:36 +01:00
Ryan Gabbard 659aa48f53 Improve documentation of safety constraints on hashable objects (#505)
* Clarify documentation for hashing

Makes clear that hashable objects need to be deeply immutable, in
practice even if not in theory.

Closes #503 .

* Use simple past tense in docs
2019-02-14 18:06:19 +01:00
Hynek Schlawack 40edb30d3a Make nicer link 2019-02-02 14:33:29 +01:00
Ryan Gabbard d2be76c964 Clear cache hash on de-serialization (#489)
* Don't cache hash codes across deserialization.

 Because the hash code cache field gets serialized and deserialized by
 Pickle, previously when you deserialize a cache_hash=True attrs object, the
 hashcode will be the hashcode the object had at serialization-time.
 However, if your object had fields with hash codes which were not
 deterministic between interpreter runs, then on a new interpreter run
 your deserialized object would have a hash code which differs from a
 newly created identical object.

 This commit fixes that by clearing the cache on deserialization. It
 needs to override the __setstate__ method to do so, so this commit
 also forbids using a custom __setstate__ on a cache_hash=True object.

Closes #482 .

* Improve exception type

* Minor tweaks to comments formatting

* Fix test for Python 2.7

* Fix error in comment

* Make nomenclature consistent for slotted/dict classes

* Remove hasattr()

* Improve comments and error message for custom __setstate__ + cache_hash=True

* Drop use of  for test classes for cache hash serialization

* Make changelog note this is a breaking change

* Make exception message point to tracking issue

* Fix test classes for Python 2.7
2019-02-02 14:32:01 +01:00
Hynek Schlawack 403178e1c1 Typo 2018-11-26 17:34:26 +01:00
Hynek Schlawack 8379adfacb Tune markup 2018-11-24 13:05:58 +01:00
Ryan Gabbard e114561a06 450 kwonly before init false (#459)
* Allow init=False attributes to follow kw_only attributes

Closes #450

* Fix changelog typo

* Update reference text for exception message

* Remove type annotations from tests

* Fix long docstring lines

* Add test with literal default
2018-11-24 13:03:27 +01:00
Matt Bullock 336d052ec9 Some new validators (#425)
* initial implementation of deep validators for iterables and dictionaries

* initial implementation of is_callable validator

* add versionadded for deep validators

* add versionadded for is_callable validator

* add tests for is_callable validator

* tweak _DeepIterable repr

* add tests for deep_iterable

* add to _DeepDictionary an initial validation that the top-level value is in fact a dictionary

* add tests for deep_dictionary validator

* apply precommit hooks

* refactor deep_dictionary to deep_mapping with optional mapping validator

* move is_callable validator up in module to allow deep validators to use it

* complete conversion from "deep dictionary" to "deep mapping"

* add changelog.d entry for #425

* fix rst formatting and normalize to semantic newlines

* add "instance_of", "deep_iterable", and "deep_mapping" validators to docs/api.rst

* add "serve-docs" tox environment to preview rendered sphinx docs

* bump versionadded for is_callable and deep validators to 18.3.0

* linting cleanup

* Revert "add "serve-docs" tox environment to preview rendered sphinx docs"

This reverts commit a2df89b788fdc31b54e604095c166b6a37c56f19.

* fix error message broken in linting fix
2018-11-07 19:33:52 -08:00
Hynek Schlawack dcfcf5e022 Add newsfragment 2018-10-19 10:21:43 +02:00
Hynek Schlawack aaeba93b06 Prepare 18.2.0 2018-09-01 06:44:34 +02:00
Hynek Schlawack 839a6054b2 Changelog polishes 2018-09-01 06:38:15 +02:00
Hynek Schlawack 73ae718ec5
Consistently use "base class" and "subclass" (#436)
Thanks to ABCs, "base class" is more Python than "superclass" and the latter is
also slightly confusing by alluding to "super" and/or being judgy.
2018-08-29 18:52:47 +02:00
Hynek Schlawack 12682192ba Use consistently autodoc syntax for arguments 2018-08-27 14:43:22 +02:00
Hynek Schlawack 746f047a27
Allow to override class vars of super classes w/ annotations (#431)
* Allow to override class vars of super classes w/ annotations

Fixes #427

* Add newsfragment
2018-08-27 13:33:40 +02:00
Kyle Altendorf 7fe111cbe2 T325 weakref with slots (#420)
* Add weakref parameter to attr.s()

#325

* Add weakref to simple_classes() strategy

* Rename changelog file with actual PR (420.change.rst)

* Add test_weakref_does_not_add_a_field()

* Add docstrings to new weakref tests

* Add missing blank line

* Correct weakref handling of __weakref__ attributes or an inherrited slot

* Correct typos and terms

* Rename to weakref_slot

* Parametrize more tests against weakref_slot True/False to expose trouble

* Check if __weakref__ has been inherited via a __dict__

* Correct copy/pasted comment

* Change weakref_slot default to True

* Tidy and correct weakref -> weakref_slot
2018-08-25 09:01:02 +02:00
Hynek Schlawack 068cd0ba4c
Allow attributes to be called property and itemgetter (#430)
* Allow attributes to be called property and itemgetter

* Add newsfragment
2018-08-21 06:42:46 +02:00
Hynek Schlawack 0121f3b23c RTD supports https for external domains now! 2018-08-20 06:48:51 +02:00
Ryan Gabbard 3e0ecbd891 Cache hash codes (#426)
* First stab at implementing hashcode caching (#423)

Currently all existing tests pass but no cache_hash tests have yet
been added.

* Existing hash tests now pass on cache_hash classes

* Add towncrier change log

* Add documentation for cache_hash

* Fixes bug with check that init=True if cache_hash=True

* Fix long lines

* Fix documentation issues

* Add test for cache_hash requiring init

* Improve test coverage

* Remove now unnecessary 'pass'

* Add periods to the end of exception strings

* Add test docstrings for cache_hash tests

* Clarify documentation of cache_hash

* Recommend that hashable classes be frozen

* Fix test references for exception messages
2018-08-20 06:46:52 +02:00
Alex Ford 123df67041 Added support for keyword-only arguments on Python 3+ [rebase] (#411)
* Added support for keyword-only attributes. Closes #106, and closes #38

(Rebases #281)

Co-authored-by: Alex Ford <fordas@uw.edu>

* Add `attr.s`-level `kw_only` flag.

Add `kw_only` flag to `attr.s` decorator, indicating that all class
attributes should be keyword-only in __init__.

Minor updates to internal interface of `Attribute` to support
evolution of attributes to `kw_only` in class factory.

Expand examples with `attr.s` level kw_only.

* Add `kw_only` to type stubs.

* Update changelog for rebased PR.

Hear ye, hear ye. A duplicate PR is born.

* Tidy docs from review.

* Tidy code from review.

* Add explicit tests of PY2 kw_only SyntaxError behavior.

* Add `PythonToOldError`, raise for kw_only on PY2.

* `Attribute._evolve` to `Attribute._assoc`.
2018-08-11 06:40:01 +02:00
Hynek Schlawack afd2584470
Implement attr.converters.default_if_none (#414)
* Implement attr.converters.default_if_none

fixes #400

* Comment out typing example for now

* Add PR newsfragment

* Fix linter
2018-07-28 16:03:41 +01:00
Hynek Schlawack a6955bff7d
Add narrative docs for type annotations (#406)
* Add narrative docs for type annotations

* Better wording

* Use better code-block types

* Add newsfragment for #238 that refers to these docs
2018-07-28 12:05:12 +01:00
George Macon 4c41099fb8 Do not copy __weakref__ from original _cls_dict (#410)
self._cls_dict["__weakref__"] holds a reference to self._cls, preventing
self._cls from being released after the new, slots-enabled class is
returned.

Fixes #407
2018-07-28 11:24:53 +01:00
Hynek Schlawack 0693f47b82 Disable hypothesis.HealthCheck.too_slow globally (#396)
* Disable hypothesis.HealthCheck.too_slow globally

Fixes #364

* Add newsfragment
2018-06-17 13:32:48 +02:00
Tin Tvrtković 908cb018f2 Feature/recursive asdict (#395)
* Fix recursive asdict.

* Blacken.

* Add tests.

* Fix docstring. Add changelog entry.

* Update 395.change.rst
2018-06-17 07:55:55 +02:00
Hynek Schlawack 2834ee4a0c
Raise DeprecationWarning when comparing subclasses (#394)
* Raise DeprecationWarning when comparing subclasses

* Grammar

* Add newsfragment
2018-06-16 17:00:45 +02:00
Hynek Schlawack 9ffb013ea7 Clean up changelog.d 2018-06-16 08:07:25 +02:00
Zac Hatfield-Dodds a3dbdfc687 Improve error for in_(a_string) with a non-string value (#383)
* Improve error for in_(a_string) with a non-string value

* Tighten exception handling and test description

* Improve changelog for Hynek

* Final changelog edit
2018-05-25 10:32:13 +02:00
Hynek Schlawack 5b5a9c4ba3 Use new slotted lingo 2018-05-03 18:00:38 +02:00
Hynek Schlawack 879f43d355 Add narrative chapter about initialization (#370)
* Add narrative chapter on initialization

* Be more explicit about defining validators both ways

* Stress that the name of default/validator != attr name

* Mention nested schemas

* Explain handling of private attributes

* Add another consequence of _ stripping

* Stress that nothing should overwrite attributes on class body

* Better wording

* typo

* Dedup examples

* Address review feedback

* Add newsfragments
2018-04-25 00:07:03 +02:00
David Euresti fc033b41a1 Annotate __init__ with type hints (#363)
* Annotate __init__ with type hints

This just adds the annotations found at run-time to the
`__annotations__` attribute of the created `__init__` function

Fixes #249

* More tests. Add return annotation

* Documentation

* This is not markdown
2018-04-06 10:36:29 +02:00
Glyph 5e46afda49
return "..." rather than raising RecursionError for repr() on a cyclic object
Fixes #95
2018-03-17 01:32:28 -07:00
Hynek Schlawack 780e1e5e1e
Add syntactic sugar for attr.ib(default=attr.Factory) (#356)
Fixes #178
2018-03-14 19:05:48 +01:00
Andy Freeland bf65b96a91 Add attr.fields_dict() (#349) 2018-03-03 15:09:05 +01:00
Hynek Schlawack 538d75f60c Retain order if these or make_class are passed an ordered dict (#343)
* Retain order if these or make_class are passed an ordered dict

Fixes #339

* Add newsfragment

* Another newsfragment

Fixes #300

* Docs and change tags

* Disable coverage and explain why

* PyPy has ordered dicts too

* Import OrderedDict only when necessary
2018-02-17 12:24:23 +01:00
Tin Tvrtković b47c6ce8b1 Eliminate __init__ overhead for frozen dict classes. (#336) 2018-01-29 07:35:01 +01:00
Hynek Schlawack dc6040f9d5 Make cell setting completely best effort (#334)
* Make cell setting completely best effort

We just try, catch any exception and warn if it doesn't work on a Python 3.
Should cover edge cases such as Jython or GAE.

Fixes #321

* Add news fragment

* Typing is hard yo
2018-01-27 21:07:14 +01:00
Hynek Schlawack 825de4f008 Make NOTHING's hash vegan (#332)
...and fit into a 32bit integer.

Fixes #331
2018-01-26 14:30:23 +01:00
Hynek Schlawack 8278088a70
Ignore __weakref__ in __setstate__ & __getstate__ (#326) 2018-01-17 13:16:39 +01:00
Hynek Schlawack 1f0d851996 Kill off old newsfragments 2018-01-16 20:28:13 +01:00
Hynek Schlawack fc2062ea0c
Do not delete attributes from class body if these is passed (#323)
Fixes #322
2018-01-16 19:09:23 +01:00
Hynek Schlawack b778e5c987 Fix release stuff 2017-12-30 09:03:45 +01:00
Hynek Schlawack 3cffdfa3dd Encourage kwargs-based initialization
ref #304
2017-12-29 09:41:33 +01:00
Hynek Schlawack ea99d26666 Clean up main directory a bit 2017-12-27 13:32:32 +01:00
Hynek Schlawack 8249305e12 Remove superfluous word 2017-12-27 12:01:08 +01:00
Hynek Schlawack d33906ab90 Better working of the consequences of #304 2017-12-27 11:59:37 +01:00
Hynek Schlawack 9e1f1360a8
Add __module__ and __qualname__ to methods, fix __name__ (#316) 2017-12-27 11:54:18 +01:00
Hynek Schlawack bc0b437e58
Rename convert to converter (#315) 2017-12-23 08:46:10 +01:00
Hynek Schlawack 051da6872a Wordsmith newsfragment 2017-12-19 08:41:06 +01:00
Kyle Altendorf 1addd3534d Make _CountingAttr empty metadata unique (#280)
* Make _CountingAttr empty metadata unique

Issue #278

* Correct st.none().map() to st.builds()

* Add 'real' and 'force coverage' tests for not None metadata

* Add changelog for pr 280

* Correct import order in tests/test_make.py

* Add back coverage force test

* Remove debug print from test/utils.py
2017-12-19 07:51:24 +01:00
Hynek Schlawack 5ed8c4a015
Fix MRO traversal with multiple inheritance (#304)
* Fix MRO traversal with multiple inheritance

* Add newsfragments
2017-12-13 15:33:44 +01:00
Yann Kaiser 9d441d70ab Fix __repr__ crashing when a member is uninitialized or deleted (#308) 2017-12-06 10:21:58 -08:00
Hynek Schlawack cd8890c744
Speed up __eq__ by generating code (#306)
* Speed up __eq__ by generating code

* Add newsfragment
2017-12-04 18:48:25 +01:00
Hynek Schlawack defa6b6f40 Fix and accelerate generated __hash__ methods (#296)
* Fix and accelerate generated __hash__ methods

We now create a method like we do for __init__ and hash also the class of the
instance.

* Add/fix news fragments

* Hash random numbers instead of the actual class

* Even simpler: let's hash the unique filename

Or rather it's hash, because hashing ints is very fast.
2017-11-30 10:16:11 +01:00
Hynek Schlawack f5b59a01f8
Handle inherited __annotations__ (#292)
* Handle inherited __annotations__

Fixes #291

* Add pr fragment
2017-11-14 06:27:50 +01:00
Hynek Schlawack a84a36d45f
Handle attrib redefs thru multiple inheritance (#287) 2017-11-11 07:09:17 +01:00
Hynek Schlawack 1e6627c9ad
Make ctypes optional (#286) 2017-11-10 17:23:53 +01:00
Hynek Schlawack aa097d62a1 Kill off merged news fragments 2017-11-08 18:44:09 +01:00
Hynek Schlawack 88aa1c897d
Add auto_attribs (#277)
Allow for attr.ib-less attribute definitions using class variable annotations.
2017-11-08 11:15:21 +01:00
Stanis Trendelenburg c1adf5cfc6 Fix pickling for instances of classes created using make_class() (#282) 2017-11-04 14:38:03 +01:00
Hynek Schlawack 3040bdabbc Refactor class creation (#272)
Instead of adding and possibly later deleting attributes, the class creation is delegated into a cleaner building pattern.
2017-10-26 12:55:34 +02:00
Hynek Schlawack f47efca44e Some changelog adjustments 2017-10-03 10:45:00 +02:00
Hynek Schlawack 8b490b8586 Stop setting attributes on class bodies (#253)
* Stop setting attributes on class bodies

This behavior has been deprecated since 16.1 and can now be removed in
accordance with our backward-compatibility policy.

* We don't need iterkeys anymore
2017-10-02 12:14:37 +02:00
Chad Dombrova 566ada9848 Basic type support (#239)
* Add support for passing a type to attr.ib() and gathering the type from PEP526-style annotations.

* Address review notes.

* More review notes.

* A few more review changes.

* Quick final fix to the changelog.
2017-09-17 16:22:49 +02:00
Hynek Schlawack 4faf5f9c26 Allow subclasses to overwrite attributes (#229)
Simply filter out all attributes from super classes that are present in the
current class.

Fixes #221
2017-08-21 00:39:34 +02:00
Hynek Schlawack 5184ecac99 Obey own naming scheme 2017-08-20 08:11:12 +02:00
Hynek Schlawack 55ae1945b3 Move changelog to towncrier (#236) 2017-08-20 07:58:08 +02:00