← Back to index

constructors_consistency.py

True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 0
FP: 0
FN: 0
Optional: 0 / 1
1"""
2Tests consistency checks between __new__ and __init__ methods.
3"""
4
5# pyright: reportInconsistentConstructor=true
6
7# Specification: https://typing.readthedocs.io/en/latest/spec/constructors.html#consistency-of-new-and-init
8
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
20class Class1:
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?
26 pass