https://pantsbuild.org/ logo
#development
Title
# development
b

bitter-ability-32190

02/01/2022, 5:49 PM
How do devs feel about https://github.com/typeddjango/pytest-mypy-plugins ๐Ÿงต ?
I'm working on some particularly picky type-annotated code, where it's really easy to "get it wrong". I'd like to add tests to ensure that certain property scopes didn't get narrowed. E.g. if property is supposed to return
str | None
(and not the accidental
str
) there's no way to enforce this. Declaring a variable of type
str | None
isn't sufficient as
mypy
is happy to "promote"
str
to fit into
str | None
.
The only way I've found so far is to
assert x is None
followed by some code after it, in which
mypy
will complain about unreachable code if
x
is type
str
.
h

hundreds-father-404

02/01/2022, 5:57 PM
+1 for me. I always thought that that was just a convience for running MyPy against your own code via
pytest
rather than having to use
pytest
+
mypy
, so I had no interest But if it's specifically to test our type hints are correct, cool!
b

bitter-ability-32190

02/01/2022, 5:58 PM
(I'll add this to the backlog and, of course, try it in a different PR)
(It'll make the test lockfile include
mypy
๐Ÿ˜… )