Wrong self type only reported upon call if using VarArgs
Open
Nobody has claimed this yet.
bug
topic-error-reporting
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Mypy does not raise an error if a method accepts nothing but a vararg list, but lacks a self parameter or staticmethod decorator.
This behavior is confusing because Mypy does catch wrong self types for regular parameters.
To Reproduce
class Class:
def method(*args: int) -> int:
return sum(args)
print(Class().method(1, 2, 3))
Expected Behavior
foo.py:2: error: Self argument missing for a non-static method (or an invalid type for self) [misc]
Actual Behavior
foo.py:5: error: Invalid self argument "Class" to attribute function "method" with type "Callable[[VarArg(int)], Any]" [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.7.0
- Mypy command-line flags:
--strict - Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9
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
No source file or test is named. Run the supplied Python 3.9 reproducer with mypy --strict, then trace the existing self-argument validation for methods annotated with VarArg. Done means the expected [misc] diagnostic is reported at the method definition rather than only when the method is called.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100