diff options
author | Hynek Schlawack <hs@ox.cx> | 2020-11-04 08:38:54 +0100 |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2020-11-04 08:40:16 +0100 |
commit | 6b4a1f1ce65162afe54e7101b263859bf8b2177e (patch) | |
tree | acb8dfa5d3b7b7ffec851a90f95919de891ef984 | |
parent | 9f7d11e415bc789c9cbab255cb9a5b8903c1b122 (diff) | |
download | attrs-6b4a1f1ce65162afe54e7101b263859bf8b2177e.tar.gz |
Tighten up mypy configuration
To prevent 9f7d11e in the future.
Add type annotations to typing example to make it pass too.
-rw-r--r-- | mypy.ini | 3 | ||||
-rw-r--r-- | tests/typing_example.py | 28 |
2 files changed, 17 insertions, 14 deletions
diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..685c025 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +disallow_untyped_defs = True +check_untyped_defs = True diff --git a/tests/typing_example.py b/tests/typing_example.py index e486dca..eb86c8f 100644 --- a/tests/typing_example.py +++ b/tests/typing_example.py @@ -85,7 +85,7 @@ c == cc # Exceptions @attr.s(auto_exc=True) class Error(Exception): - x = attr.ib() + x: int = attr.ib() try: @@ -153,8 +153,8 @@ class Validated: attr.validators.instance_of(C), attr.validators.instance_of(D) ), ) - e = attr.ib(validator=attr.validators.matches_re(r"foo")) - f = attr.ib( + e: str = attr.ib(validator=attr.validators.matches_re(r"foo")) + f: str = attr.ib( validator=attr.validators.matches_re(r"foo", flags=42, func=re.search) ) @@ -172,27 +172,27 @@ class Validated: # Custom repr() @attr.s class WithCustomRepr: - a = attr.ib(repr=True) - b = attr.ib(repr=False) - c = attr.ib(repr=lambda value: "c is for cookie") - d = attr.ib(repr=str) + a: int = attr.ib(repr=True) + b: str = attr.ib(repr=False) + c: str = attr.ib(repr=lambda value: "c is for cookie") + d: bool = attr.ib(repr=str) # Check some of our own types @attr.s(eq=True, order=False) class OrderFlags: - a = attr.ib(eq=False, order=False) - b = attr.ib(eq=True, order=True) + a: int = attr.ib(eq=False, order=False) + b: int = attr.ib(eq=True, order=True) # on_setattr hooks @attr.s(on_setattr=attr.setters.validate) class ValidatedSetter: - a = attr.ib() - b = attr.ib(on_setattr=attr.setters.NO_OP) - c = attr.ib(on_setattr=attr.setters.frozen) - d = attr.ib(on_setattr=[attr.setters.convert, attr.setters.validate]) - d = attr.ib( + a: int + b: str = attr.ib(on_setattr=attr.setters.NO_OP) + c: bool = attr.ib(on_setattr=attr.setters.frozen) + d: int = attr.ib(on_setattr=[attr.setters.convert, attr.setters.validate]) + e: bool = attr.ib( on_setattr=attr.setters.pipe( attr.setters.convert, attr.setters.validate ) |