Commit Graph

68 Commits

Author SHA1 Message Date
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
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
Sagi c17ae9da7a Added Core function parameter in func defintion (#446) 2018-09-17 16:45:53 +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
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 7a242a1bf8 Mark error in example 2018-05-01 12:18:26 +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
Andy Freeland bf65b96a91 Add attr.fields_dict() (#349) 2018-03-03 15:09:05 +01:00
Hynek Schlawack 75cdf8fe91 Add missing argument to signature
Fixes #333
2018-01-26 12:05:49 +01:00
Hynek Schlawack bc0b437e58
Rename convert to converter (#315) 2017-12-23 08:46:10 +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
Hynek Schlawack 3d3d49b4dd Prepare for narrative docs (#275) 2017-10-26 17:55:45 +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 e31cbe5cfd Add more docs about __attrs_post_init__ (#235)
* Add more docs about __attrs_post_init__

* Grammer
2017-08-18 20:43:38 +02:00
Hynek Schlawack 04e171aa4c Document validator syntax more prominently 2017-05-22 16:42:40 -07:00
Hynek Schlawack 8ed593b954 Better way to fix evolve docs 2017-05-22 16:23:18 -07:00
Hynek Schlawack b7919d0ddd Fix doc build on sphinx 1.6.1 2017-05-22 16:16:12 -07:00
Andre Dieb 461e1b2aab [RFC] Enhancement/one of validator (#181) 2017-05-16 10:36:42 +02:00
Hynek Schlawack a328e67169 Add takes_self to Factory and @_CountingAttr.default (#189)
* Add takes_self to Factory and @_CountingAttr.default

Fixes #165

* Add dark @Tinche magic
2017-05-16 09:36:39 +02:00
Hynek Schlawack fbe0bd5967 Make optional support lists of validators (#186) 2017-05-12 23:02:07 +02:00
Timothy Emiola fdfd51e249 Allow optional conversion (#173)
Fixes #105
2017-05-10 15:37:50 +02:00
Tin Tvrtković b79a49e9a4 Fix evolve (cont) (#182) 2017-05-04 13:20:39 +02:00
Hynek Schlawack 6509da85e1 Add docstring to _CountingAttr.validator 2017-03-24 08:54:02 +01:00
Hynek Schlawack 96fc8cb815 Stop living in the past
...and move all aux tests to 3.6.
2017-03-04 07:52:33 +01:00
Hynek Schlawack f560500886 Fix hashing behavior (#142) 2017-02-19 09:51:43 +01:00
Hynek Schlawack 37d38c4dc3 Allow inline definitions of validators using a decorator
Also make previous changes for multiple validators backward-compatible.
2017-02-11 16:56:56 +01:00
Hynek Schlawack 735ba4121b Move assoc to deprecated section 2017-02-03 11:03:16 +01:00
Tin Tvrtković 0d3cf3f624 Evolve and docs. (#135)
assoc is now deprecated in favor of evolve.
2017-01-21 17:11:45 +01:00
Hynek Schlawack b0942e1b2e Add str argument to @attr.s
Fixes #112
2016-11-20 15:52:11 +01:00
Tin Tvrtković 0fac9215b8 Introduce attribute metadata. (#96) 2016-11-19 09:47:03 +01:00
inso 1b419e304b Add attr.astuple
Fixes #77 and fixes #78
2016-09-11 08:55:30 +02:00
Hynek Schlawack 62cb2e7347 Document new method of accessing attributes 2016-09-10 19:55:27 +02:00
Hynek Schlawack adfdbf9560 Stop using deprecated APIs (#86)
Also use nicer exceptions that subclass the old ones.
2016-09-10 19:14:34 +02:00
Hynek Schlawack 41d8cce09d Add a philosophy section (#73)
Also expand the example class a little bit to stress that we're not just
about data containers.
2016-08-30 12:12:02 +02:00
Hynek Schlawack cfa6d2e99f Implement immutability (#60) 2016-08-20 18:45:15 +02:00
Hynek Schlawack 24e60944ec Add better serious business aliases 2016-08-16 12:18:03 +02:00
JesseWeinstein 2f9826c8dd Doc typo fixes (#56)
Native English speaker fixes
2016-08-15 10:00:23 +02:00
Hynek Schlawack 28204bef92 Deprecate Attribute instances on decorated classes
The changelog deprecation error explains it best.  It's to avoid
confusing errors if some attribute hasn't been initialized for whatever
reason (usually `init=False` + typo).
2016-08-08 12:11:06 +02:00
Tin Tvrtkovic cfc42ef222 Add slots docs. 2016-03-28 21:05:00 +02:00
Christopher Armstrong 20357d4368 fix doctests and lint 2015-11-19 13:59:25 +01:00
Samuel A. Falvo II 765a97466d Review feedback 2015-07-26 11:29:54 +02:00
Hynek Schlawack d964845899 Make __attrs_attrs__ a tuple
Having a mutable and rather heavy data structure for something that is supposed
to be immutable doesn't seem to make sense.
2015-03-23 09:17:54 +01:00
Hynek Schlawack 2a91800150 Add include and exclude filter helpers 2015-02-20 16:34:21 +01:00
Hynek Schlawack fba942270b Stay happy and positive
Closes #6
2015-02-20 13:29:47 +01:00
Hynek Schlawack a185bbfdfb Add option to disable validators globally 2015-02-20 11:30:46 +01:00
Hynek Schlawack 445b6b2e00 Add these argument to attr.s
Useful for third party classes and when using properties.

Based on feedback by @econchick & @hawkowl
2015-02-08 16:31:16 +01:00
Hynek Schlawack c8c7a60389 Rename valid to validate
valid kind of implies a boolean return code.
2015-02-02 14:04:47 +01:00