Description
Bug Report
TLDR: If you have a zero-arg constructor of a native type, stubtest complains that stub does not have *args argument "args"
.
From what I understand, constructors of native types will always have a __textsignature__
of __init__($self, /, *args, **kwargs)
. Instead, the constructor's signature is actually stored on the type's __textsignature__
.
However, stubtest never reads the type's signature, and so treats all native constructors as having a (self, *args, **kwargs)
constructor. Most of the time this doesn't matter, as _verify_signature
allows the stub's type signature to be more precise than the runtime one. However, if the stub's constructor takes no arguments, then we get an error.
To Reproduce
Create the following "foo.py" and "foo.pyi"
# In foo.py:
SomeType = object
# In foo.pyi:
class SomeType:
def __init__(self): ...
Then run stubtest with stubtest foo
.
Expected Behaviour
I would expect this to use the type's signature, and not produce any error.
Actual Behaviour
Instead, we get an error about a missing *args
:
error: foo.SomeType.__init__ is inconsistent, stub does not have *args argument "args"
Stub: in file foo.pyi:2
None
Runtime:
def (self, /, *args, **kwargs)
Found 1 error (checked 1 module)
Your Environment
- Mypy version used: 1.11.1
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.1012 on Linux (WSL)