Closed
Description
Bug Report
Using a frozen dataclass with an attribute typed as a TypeAlias
for a Callable
results in mypy treating the attribute as the return value. See reproduce for more easy to understand example.
To Reproduce
from dataclasses import dataclass
from typing import Callable, TypeAlias
Func: TypeAlias = Callable[..., None]
@dataclass(frozen=True, eq=False)
class Foo:
bar: Func
def example() -> None:
pass
Foo(bar=example).bar()
results in
test.py:13:1: error: "None" not callable [misc]
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
mypy should pass
Actual Behavior
Removing frozen=True
causes mypy to pass this code.
Your Environment
- Mypy version used: 0.931
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini
(and other config files):
python_version=3.10
platform=linux
plugins=pydantic.mypy, sqlalchemy.ext.mypy.plugin
show_column_numbers=True
show_error_codes=True
# show error messages from unrelated files
follow_imports=normal
# show errors about unsatisfied imports
ignore_missing_imports = False
# be strict
disallow_untyped_calls=True
warn_return_any=True
strict_optional=True
warn_no_return=True
warn_redundant_casts=True
warn_unused_ignores=True
# The following are off by default. Flip them on if you feel
# adventurous.
disallow_untyped_defs=True
check_untyped_defs=True
- Python version used: 3.10.2
- Operating system and version: Ubuntu 20.04