Skip to content

Commit 6b4a1f1

Browse files
committed
Tighten up mypy configuration
To prevent 9f7d11e in the future. Add type annotations to typing example to make it pass too.
1 parent 9f7d11e commit 6b4a1f1

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
disallow_untyped_defs = True
3+
check_untyped_defs = True

tests/typing_example.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class HH(DD, EE):
8585
# Exceptions
8686
@attr.s(auto_exc=True)
8787
class Error(Exception):
88-
x = attr.ib()
88+
x: int = attr.ib()
8989

9090

9191
try:
@@ -153,8 +153,8 @@ class Validated:
153153
attr.validators.instance_of(C), attr.validators.instance_of(D)
154154
),
155155
)
156-
e = attr.ib(validator=attr.validators.matches_re(r"foo"))
157-
f = attr.ib(
156+
e: str = attr.ib(validator=attr.validators.matches_re(r"foo"))
157+
f: str = attr.ib(
158158
validator=attr.validators.matches_re(r"foo", flags=42, func=re.search)
159159
)
160160

@@ -172,27 +172,27 @@ class Validated:
172172
# Custom repr()
173173
@attr.s
174174
class WithCustomRepr:
175-
a = attr.ib(repr=True)
176-
b = attr.ib(repr=False)
177-
c = attr.ib(repr=lambda value: "c is for cookie")
178-
d = attr.ib(repr=str)
175+
a: int = attr.ib(repr=True)
176+
b: str = attr.ib(repr=False)
177+
c: str = attr.ib(repr=lambda value: "c is for cookie")
178+
d: bool = attr.ib(repr=str)
179179

180180

181181
# Check some of our own types
182182
@attr.s(eq=True, order=False)
183183
class OrderFlags:
184-
a = attr.ib(eq=False, order=False)
185-
b = attr.ib(eq=True, order=True)
184+
a: int = attr.ib(eq=False, order=False)
185+
b: int = attr.ib(eq=True, order=True)
186186

187187

188188
# on_setattr hooks
189189
@attr.s(on_setattr=attr.setters.validate)
190190
class ValidatedSetter:
191-
a = attr.ib()
192-
b = attr.ib(on_setattr=attr.setters.NO_OP)
193-
c = attr.ib(on_setattr=attr.setters.frozen)
194-
d = attr.ib(on_setattr=[attr.setters.convert, attr.setters.validate])
195-
d = attr.ib(
191+
a: int
192+
b: str = attr.ib(on_setattr=attr.setters.NO_OP)
193+
c: bool = attr.ib(on_setattr=attr.setters.frozen)
194+
d: int = attr.ib(on_setattr=[attr.setters.convert, attr.setters.validate])
195+
e: bool = attr.ib(
196196
on_setattr=attr.setters.pipe(
197197
attr.setters.convert, attr.setters.validate
198198
)

0 commit comments

Comments
 (0)