Since 1.6.0 TypeVar with bound types fails to match with Callable of the same bound types
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Did not occur prior to 1.6.0.
https://github.com/python-cmd2/cmd2/actions/runs/6699406223/job/18203570049
Got the following error with mypy:
cmd2/cmd2.py: note: In member "_build_parser" of class "Cmd":
cmd2/cmd2.py:699:46: error: Argument 1 has incompatible type "CommandParent"; expected "Union[Type[Cmd], Type[CommandSet]]" [arg-type]
Found 1 error in 1 file (checked 18 source files)
where CommandParent is a TypeVar declared as:
CommandParent = TypeVar('CommandParent', bound=Union['cmd2.Cmd', CommandSet])
To Reproduce
https://github.com/python-cmd2/cmd2/blob/8d88c357ca0764b114c68d8175d2cd33146b83d7/cmd2/cmd2.py#L694
Expected Behavior
Since CommandParent is bound to the expected type, this shouldn't be an error
Actual Behavior
I get the error above.
Your Environment
- Mypy version used: 1.6.1
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.8, 3.9,3.10,3.11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure from cmd2/cmd2.py around line 694 using mypy 1.6.1 and the reported Python versions. Compare the TypeVar bound with the Callable argument handling, then verify that the reported compatible types no longer produce the arg-type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100