Commit Graph

15 Commits

Author SHA1 Message Date
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
Bruno Oliveira e2b02ec39e Fix default values that are not comparable with '==' (#586)
Fix #585
2019-10-15 06:56:12 +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
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 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
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 a372d51b7b
Fade to Black (#392) 2018-06-10 19:40:07 +02:00
Łukasz Langa 7cb8c82762 Support `from typing import ClassVar` (#367)
* Support `from typing import ClassVar`

Also updated the docstring to reflect why exactly we're doing what we're doing.
The previous comment was incorrect (`typing` is already imported in
applications using annotations).

I added `t.ClassVar` as well which is the only third alternative import I found
in use for typing-related classes.

Fixes #361

* Tests, docstrings, et al.
2018-04-23 15:54:47 +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
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 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 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 4a19d9b14d Add safe-guard against collecting too much 2017-10-06 14:38:23 +02:00
Hynek Schlawack 03c10ad0ef Use new serious biz names in internal code (#257)
* Use new serious biz names

* Use offical API in tests where possible

* Fix flake8
2017-10-02 19:32:10 +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