Commit Graph

15 Commits

Author SHA1 Message Date
Hynek Schlawack 6b4a1f1ce6 Tighten up mypy configuration
To prevent 9f7d11e in the future.

Add type annotations to typing example to make it pass too.
2020-11-04 08:40:16 +01:00
Hynek Schlawack 56c73081c5 Add missing collect_by_mro to typing stubs
Fixes #711
2020-11-03 10:10:43 +01:00
Stefan Scherfke 0eae613ce1
Add hooks for field transformation and for asdict serialization (#653) 2020-10-15 09:33:59 +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 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 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
David Euresti 08bbaabaca Fix some typing issues (#581)
* Typecheck stubs in CI and fix type errors.  Fixes #578

* Add overloads to instance_of definition.

Improves #576
2019-09-26 06:49:15 +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 9bc319b7c8 Add example for matches_re typing 2019-09-09 11:11:50 +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
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
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
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
Chad Dombrova de104e016b Add PEP484 stubs (#238)
* Add PEP484 stubs

* Deploy .pyi stubs alongside .py files.

This is the recommended approach for 3rd party stubs.
See: https://github.com/python/typing/issues/84#issuecomment-317217346

* Add support for the new type argument.

* Add tests for stubs and address a few issues.

* Improve declaration of private vs public objects in stubs

* More stub tests

* Separate the stub tests into their own tox env

it does not make sense to test the stubs in multiple python *runtime* environments (e.g. python 3.5, 3.6, pypy3) because the results of static analysis wrt attrs is not dependent on the runtime.  Moreover, mypy is not installing correctly in pypy3 which has nothing to do with attrs.

* Update the manifest with stub files

* Remove mypy from the dev requirements

* Allow _CountingAttr to be instantiated, but not Attribute.

* Incorporate defaults into attr.ib typing

* Fix a bug with validators.and_

* Add more tests

* Remove _CountingAttr from public interface

It is crucial to ensure that make_class() works with attr.ib(), as a result we no longer have any functions that care about _CountingAttr.

* Lie about return type of Factory

this allows for an abbreviated idiom: `x: List[int] = Factory(list)`

* Add tox stubs env to travis

* used the wrong comment character in mypy tests

* Improve overloads using PyCharm order-based approach

overloads are pretty broken in mypy.  the best we can do for now is target PyCharm, which is much more forgiving.

* Remove features not yet working in mypy. Document remaining issues.

* Test stubs against euresti fork of mypy with attrs plugin

Copied the pytest plugin from mypy for testing annotations: It is not an officially supported API and using the plugin from mypy could break after any update.

* Add some types and TypeVars to some types. Make tests pass

* Suppress warnings about named attribute access from fields()

e.g.  fields(C).x
Eventually it would be good to add support for returning NamedTuple from the mypy plugin

* Add WIP mypy-doctest plugin

* Deal with a few remaining type issues in the docs

* sphinx doctest: don't turn warnings into errors.

doing so makes the tests abort after the first failed group.

* Update "type: ignore" comments to reflect issues fixed in mypy plugin

* doctest2: improve output formatting

* Update manifest

* static tests: use inline error declarations

* More tests

* Tests passing (with notes about remaining issues)

* Attempt to get latest plugin from euresti working

* Issues fixed.

Had to place calls to attr.ib under a class definition.

* Deal with a PyCharm bug

* Minor test improvements

* Make tests prettier

* Use 2 decorators instead of 3

* doctest2: add support for skipping mypy tests

* Add tests for inheritance, eq, and cmp

* Add fixmes and todos

* Rename convert to converter

* Attribute.validator is always a single validator

* Conform stubs to typeshed coding style

And add auto_attrib kw

* backport style fixes from typeshed

* Add test cases to cover forward references and Any

* Add fixes for forward references and Any

* Address typeshed review notes

* Use Sequence instead of List/Tuple for validator arg

list and tuple are invariant and so prevent passing subtypes of _ValidatorType

* backports changes from typeshed #1914

* backport changes from typeshed #1933

* Prevent mypy tests from getting picked up

Evidently the discovery rules changed recently for pytest.

* make our doctest extension compatible with latest sphinx

* Adjustments to the tests

* Fix flake and manifest tests (hopefully)

* Fix tests on pypy3 (hopefully)

* Update stubs from typeshed

Also update tests.

* Make PEP 561-compliant

* minor cleanup

* Consolidate stub support files into stub directory

In preparation for removing them from the pyi_stubs branch.

* Get tests passing

This is a final test of the current stubs before moving the stub tests to a new branch.

* Revert stub test additions

Replace with a simple mypy pass/fail test

* get pre-commit passing

* Address review feedback

* Move typing test up in tox envlist
2018-07-12 12:19:24 +02:00