We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug Report
Despite an if x is not None check, mypy suddenly believes x could be None inside a function definition.
if x is not None
mypy
x
None
To Reproduce
from functools import wraps from collections.abc import Callable from typing import TypeVar, ParamSpec, Optional P = ParamSpec("P") R = TypeVar("R") def foo(func: Callable[P, R], before_func: Optional[Callable[P, None]] = None) -> Callable[P, R]: if before_func is not None: reveal_type(before_func) # <-- Revealed type is "def (*Any, **Any) -> Any" @wraps(func) # problem persists when removing @wraps def wrapper(*args, **kwargs): reveal_type(before_func) # Revealed type is "Union[def (*Any, **Any) -> Any, None]" before_func(*args, **kwargs) # error: "None" not callable return func(*args, **kwargs) return wrapper return func
Your Environment
[tool.mypy] allow_redefinition = true color_output = true error_summary = true files = ["src/", "test/"] plugins = "numpy.typing.mypy_plugin" pretty = true python_version = "3.10" check_untyped_defs = true show_column_numbers = true show_error_codes = true warn_unused_ignores = true #disallow_untyped_defs = true disallow_incomplete_defs = true
The text was updated successfully, but these errors were encountered:
Duplicate of #2608
Sorry, something went wrong.
No branches or pull requests
Bug Report
Despite an
if x is not None
check,mypy
suddenly believesx
could beNone
inside a function definition.To Reproduce
Your Environment
Mypy configuration
The text was updated successfully, but these errors were encountered: