Commit Graph

27 Commits

Author SHA1 Message Date
Tin Tvrtković c7308a66ef
Flesh out resolve_types (#1099)
* Flesh out resolve_types

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add changelog entry

* Fix flake?

* Update 1099.change.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hynek Schlawack <hs@ox.cx>
2023-03-18 19:31:15 +01:00
Hynek Schlawack 3843452516
Replace omnipresent pytest.mark.parametrize("(slots|frozen)" w/ fixture (#1002)
Replace omnipresent pytest.mark.parametrize("(slots|frozen)", [True, False]) w/ fixture
2022-08-11 09:35:39 +02:00
Hynek Schlawack 08f8319efe
Drop Python 3.5 (#988)
* Drop Python 3.5

Less than 0.5% of our downloads are 3.5 and it allows us to simplify A LOT of code.

Fixes #965

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

* Run 3.6 under coverage

* Add newsfragment

* Probably don't need 3.7 for coverage

* Everything is ordered!

* pre-commit autoupdate, add yesqa
2022-08-05 09:48:00 +02:00
Tim Gates e3f231090a
docs: fix simple typo, coverter -> converter (#977) 2022-07-03 06:52:29 +02:00
Hynek Schlawack a18b3957d5
Add support for Python 3.11 (#969)
* Add support for Python 3.11

Co-authored-by: Tin Tvrtković <tinchester@gmail.com>

* Tin/py311 (#973)

* Fix test_slots::TestPickle::test_no_getstate_setstate_for_dict_classes

* Fix annotations

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Tweak tests for 3.10

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Tweak tests some more

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Co-authored-by: Tin Tvrtković <tinchester@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-06-24 11:37:40 +02:00
Hynek Schlawack 980c8b04f5
Drop Python 2.7 (#936)
* Drop Python 2.7

The tooling situation around Python 2 has deteriorate to such a degree that
upholding compatibility is not tenable anymore for a volunteer-run project.

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

* Add newsfragment

* Run Python 3.5 under coverage to make up for Python 2.7

* Wait for py35 in parallel

* Remove fullmatch kludge

* Remove Python 2-specific code

* Revert empty slot test

Also disable pyupgrade on that file.

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

* We DO run under 3.5

* Remove __qualname__ workarounds

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update changelog.d/936.breaking.rst

Co-authored-by: Tin Tvrtković <tinchester@gmail.com>

* Compare methods using is

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tin Tvrtković <tinchester@gmail.com>
2022-03-21 08:47:47 +01:00
Hynek Schlawack 046beaaaaa Apply SPDX IDs 2021-12-27 09:29:09 +01:00
David Euresti f31bb2850a
Fix bug in resolve_types with subclasses (#843)
* Fix bug in resolve_types with subclasses

* lint

* changelog

* lint again, like we did last summer

* Moar coverage

* lint ... why

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2021-09-19 21:04:55 +02:00
Hynek Schlawack e01ddbe307
Detect ClassVars coming from typing_extensions (#782)
* Detect ClassVars coming from typing_extensions

* Add newsfragment
2021-03-20 18:02:59 +01:00
Hynek Schlawack 03d3fc7a71
Add Python 3.10 support (#763)
* Add Python 3.10 support

Python 3.10 has string types everywhere and that has unmasked a bunch of
bugs/edge cases in our code.

Especially the hooks code need a resolving helper for string types. I'm leaving
that for a separate PR.

Fixes #716

* More robust quote handling

* Use resolve_types decorator where possible

* Use a helper for __init__ annotations

* Add test for various ClassVars
2021-02-22 12:56:44 +01:00
David Euresti 1499c77e79
Fix issue with get_type_hints(cls.__init__) and refactor (#760)
* Fix issue with get_type_hints(cls.__init__)

* Refactor

* Improve coverage
2021-02-19 06:50:41 +01:00
Nicholas Coltharp e09b1d6423
Infer type annotations from converters (#710)
* Infer annotations from converters

* Use semantic newlines

* Add 787.change.rst

* Don't let type annotations override converters

* Make pipe() infer type annotations

* Use PY2 instead of sys.versioninfo >= (3, 3)

* Avert crashing with a nullary converter

* Small doc change

* Add type inference for optional()

* Make pipe() annotations actually work

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2020-12-13 16:30:06 +01: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
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