How do devs feel about <https://github.com/typeddj...
# development
b
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
+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
(I'll add this to the backlog and, of course, try it in a different PR)
(It'll make the test lockfile include
mypy
๐Ÿ˜… )