I want to suggest adding the following test to the conformance test suite:
class Getter[T]:
def get[S=None](self, default: S = None) -> T | S: ... # OK
def test(arg: Getter[str]) -> None:
result: str = arg.get() # type: ignore
- Since the default argument value is assignable to the default type var type,
def get is well-defined
arg.get() implicitly uses None of type None as the argument. Therefore, we have an implicit constraint S <: None when .get is called without explicit default.
Therefore, result: str = arg.get() should raise an assignment type error (str | None not assignalbe to str).
Currently, only pyright succeeds on this test, and type checker results diverge.
pyright: no errors (true negative on def get, true positive on result) (pyright playground)
mypy: false positive on def get, false negative on result.
ty: false positive on def get, true positive on result. (playground)
pyrefly: false positive on def get, false negative on result (playground)
zuban: false postive on def get, false negative on result.
Related Issues
I want to suggest adding the following test to the conformance test suite:
def getis well-definedarg.get()implicitly usesNoneof typeNoneas the argument. Therefore, we have an implicit constraintS <: Nonewhen.getis called without explicit default.Therefore,
result: str = arg.get()should raise anassignmenttype error (str | Nonenot assignalbe tostr).Currently, only
pyrightsucceeds on this test, and type checker results diverge.pyright: no errors (true negative ondef get, true positive onresult) (pyright playground)mypy: false positive ondef get, false negative onresult.ty: false positive ondef get, true positive onresult. (playground)pyrefly: false positive ondef get, false negative onresult(playground)zuban: false postive ondef get, false negative onresult.Related Issues
invalid-parameter-defaulterror from generic with default ofNoneastral-sh/ty#592