-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
Description
Bug Report
For my compiled extension, I have introduced a NewType
to prevent confusion with other int
-like arguments. So I have something like this:
from typing import NewType
FooType = NewType('FooType', int)
def foo(x: FooType, /) -> FooType: ...
stubtest rightfully complains that this does not exist at runtime:
$ pip install --no-build-isolation . && stubtest newtype --ignore-disjoint-bases
error: newtype.newtype.FooType is not present at runtime
Stub: in file .../venv/lib64/python3.13/site-packages/newtype/newtype.pyi:3
<TypeInfo newtype.newtype.FooType>
Runtime:
MISSING
so I added it to the extension (as the Py_mod_exec
function for the module):
static int
newtype_mod_exec(PyObject *module)
{
PyObject *int_obj = (PyObject *)&PyLong_Type;
return PyModule_AddObjectRef(module, "FooType", int_obj);
}
Strictly speaking, this is incorrect because NewType
at runtime is supposed to produce a lambda that returns its argument directly. However, stubtest 1.17.1 and older are happy with it.
To Reproduce
Please see the simplified example repo here.
Expected Behavior
No complaints from stubtest
.
Actual Behavior
stubtest
1.18.1 now complains about the signature:
$ pip install --no-build-isolation . && stubtest newtype --ignore-disjoint-bases
error: newtype.newtype.FooType.__init__ is inconsistent, runtime does not have parameter "item"
Stub: in file .../venv/lib64/python3.13/site-packages/newtype/newtype.pyi:-1
def (self: newtype.newtype.FooType, item: builtins.int)
Runtime:
def (self)
Your Environment
- Mypy version used: 1.17.1/1.18.1
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.13.7