Closed
Description
Bug Report
To Reproduce
This code:
import dataclasses as dc
from enum import Enum
from typing import cast, Any, Callable, Dict, List
class ScalingDirection(Enum):
SCALE_UP = 'up'
SCALE_DOWN = 'down'
@dc.dataclass
class InstanceScalingStatus:
label: str
scaling_check: Callable[[ScalingDirection], bool]
is_scaling_finished: bool = False
def _check_scaling_states(scaling_states: Dict[str, InstanceScalingStatus],
scaling_direction: ScalingDirection) -> bool:
for name, scaling_state in scaling_states.items():
if scaling_state.scaling_check(scaling_direction):
scaling_state.is_scaling_finished = True
not_yet_scaled: List[str] = [state.label for state in scaling_states.values() if not state.is_scaling_finished]
if len(not_yet_scaled) > 0:
return False
return True
Expected Behavior
The scaling_state.scaling_check(scaling_direction)
is not a function call on an object. There's no self
and the Callable clearly states it only takes a single argument. It's a de-reference of a attribute that points to a callable, and call to that callable. It works, no other linter we use complains about this syntax. I belive mypy
shouldn't either.
Actual Behavior
Fails with:
→ mypy --version
mypy 0.800
→ mypy test2.py
test2.py:22: error: Invalid self argument "InstanceScalingStatus" to attribute function "scaling_check" with type "Callable[[ScalingDirection], bool]"
test2.py:22: error: Too many arguments
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
0.800
- Mypy command-line flags:
None
- Mypy configuration options from
mypy.ini
(and other config files):None
- Python version used:
3.8.3
- Operating system and version:
Windows 10 / WSL 1 / FedoraRemix 31