typing: set warn_unreachable
This makes mypy raise an error whenever it detects code which is
statically unreachable, e.g.
x: int
if isinstance(x, str):
... # Statement is unreachable [unreachable]
This is really neat and finds quite a few logic and typing bugs.
Sometimes the code is intentionally unreachable in terms of types, e.g.
raising TypeError when a function is given an argument with a wrong
type. In these cases a `type: ignore[unreachable]` is needed, but I
think it's a nice code hint.
This commit is contained in:
@@ -635,8 +635,8 @@ def _init_checker_class() -> "Type[doctest.OutputChecker]":
|
||||
return got
|
||||
offset = 0
|
||||
for w, g in zip(wants, gots):
|
||||
fraction = w.group("fraction")
|
||||
exponent = w.group("exponent1")
|
||||
fraction = w.group("fraction") # type: Optional[str]
|
||||
exponent = w.group("exponent1") # type: Optional[str]
|
||||
if exponent is None:
|
||||
exponent = w.group("exponent2")
|
||||
if fraction is None:
|
||||
|
||||
Reference in New Issue
Block a user