constructors_call_new
error
Constructor call type mismatch with specialized generic class
When a generic class is called with explicit type arguments (e.g. Class1int(1.0)), Basilisk substitutes the type parameters into the __new__ method signature and checks that the provided arguments are compatible.
This rule covers two cases:
1. **Argument type mismatch after substitution**: The __new__ method has a parameter typed with a type variable (e.g. x: T), and after substituting the type argument (e.g. T=int), the provided argument is incompatible (e.g. 1.0 is float, not int).
2. **Explicit cls parameter type mismatch**: The __new__ method has an explicitly typed cls parameter (e.g. cls: typeClass11[int]), and the class is called with different type arguments (e.g. Class11str()).
class Class1(Generic[T]):
def __new__(cls, x: T) -> Self:
return super().__new__(cls)
Class1[int](1.0) # E: float is not compatible with int
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
constructors_call_new down per-file or per-path from your editor or
pyproject.toml, or fix the code
so it type-checks. See the Type System rules and
the complete diagnostic reference.
Canonical URL: https://www.basilisk-python.dev/errors/constructors_call_new