mypyc
mypyc copied to clipboard
Local variable "p" has inferred type None; add an annotation
It's unclear to me mypyc thinks it needs an explicit annotation here
def bar() -> str | None:
return "asdf"
def foo() -> None:
p = bar()
if p is None:
print(f"{p}")
Came up in https://github.com/psf/black/pull/4015
This seems like a feature in mypyc and a bug in mypy! This error was intentionally introduced in #7482 to force a compilation failure. The underlying issue in mypy is #5423.
python/mypy#5423 was fixed but this is still happening. The best course of action may be to accept the None type.
I think this error is pretty reasonable when it happens, seems fine to just focus on root causes in binder etc