Commit Graph

270 Commits

Author SHA1 Message Date
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