Skip to content

Too many arguments / Invalid self argument when referencing callable attribute of an object. #9975

Description

@mkielar

Bug Report

To Reproduce

This code:

importdataclassesasdcfromenumimportEnumfromtypingimportcast, Any, Callable, Dict, ListclassScalingDirection(Enum):
SCALE_UP='up'SCALE_DOWN='down'@dc.dataclassclassInstanceScalingStatus:
label: strscaling_check: Callable[[ScalingDirection], bool]
is_scaling_finished: bool=Falsedef_check_scaling_states(scaling_states: Dict[str, InstanceScalingStatus],
scaling_direction: ScalingDirection) ->bool:
forname, scaling_stateinscaling_states.items():
ifscaling_state.scaling_check(scaling_direction):
scaling_state.is_scaling_finished=Truenot_yet_scaled: List[str] = [state.labelforstateinscaling_states.values() ifnotstate.is_scaling_finished]
iflen(not_yet_scaled) >0:
returnFalsereturnTrue

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions