I noticed today that @overload doesn't seem to work with __init_subclass__.
Here's a reproduction of the error. It passes mypy, but pyright reports errors on the last line:
from typing import overload
class Base:
@overload
def __init_subclass__(cls, x: str) -> None: ...
@overload
def __init_subclass__(cls, x: int) -> None: ...
def __init_subclass__(cls, x: int | str) -> None: ...
class Subclass(Base, x=3): ...
The specific errors are:
error: Incorrect keyword arguments for __init_subclass__ method (reportGeneralTypeIssues)
error: No overloads for "__init_subclass__" match the provided arguments (reportCallIssue)
error: Argument of type "Literal[3]" cannot be assigned to parameter "x" of type "str" in function "__init_subclass__"
"Literal[3]" is incompatible with "str" (reportArgumentType)
The error vanish if I swap the order of the two overloads, which seems to indicate that pyright is only matching against the first one.
Hello!
I noticed today that
@overload
doesn't seem to work with__init_subclass__
.Here's a reproduction of the error. It passes
mypy
, butpyright
reports errors on the last line:The specific errors are:
The error vanish if I swap the order of the two overloads, which seems to indicate that
pyright
is only matching against the first one.Thanks!!