← Back to index
constructors_consistency.py
TP: 0
FP: 0
FN: 0
Optional: 0 / 1
2Tests consistency checks between __new__ and __init__ methods.
5# pyright: reportInconsistentConstructor=true
7# Specification: https://typing.readthedocs.io/en/latest/spec/constructors.html#consistency-of-new-and-init
9# Note: This functionality is optional in the typing spec, and conformant
10# type checkers are not required to implement it.
13# > Type checkers may optionally validate that the __new__ and __init__
14# > methods for a class have consistent signatures.
17from typing import Self
21 def __new__(cls) -> Self:
22 return super().__new__(cls)
24 # Type error: __new__ and __init__ have inconsistent signatures
25 def __init__(self, x: str) -> None: # E?