Skip to content

Commit

Permalink
Tighten up mypy configuration
Browse files Browse the repository at this point in the history
To prevent 9f7d11e in the future.

Add type annotations to typing example to make it pass too.
  • Loading branch information
hynek committed Nov 4, 2020
1 parent 9f7d11e commit 6b4a1f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
disallow_untyped_defs = True
check_untyped_defs = True
28 changes: 14 additions & 14 deletions tests/typing_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class HH(DD, EE):
# Exceptions
@attr.s(auto_exc=True)
class Error(Exception):
x = attr.ib()
x: int = attr.ib()


try:
Expand Down Expand Up @@ -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)
)

Expand All @@ -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
)
Expand Down

0 comments on commit 6b4a1f1

Please sign in to comment.