Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions conformance/results/mypy/classes_override.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
conformant = "Pass"
conformant = "Partial"
notes = """
Does not honor `@override` compatibility checks for `__init__` and `__new__`:
the incompatible constructor overrides in `ChildC2` are not flagged.
"""
output = """
classes_override.py:53: error: Method "method3" is marked as an override, but no base method was found with this name [misc]
classes_override.py:56: error: Method "method4" is marked as an override, but no base method was found with this name [misc]
classes_override.py:79: error: Method "static_method1" is marked as an override, but no base method was found with this name [misc]
classes_override.py:84: error: Method "class_method1" is marked as an override, but no base method was found with this name [misc]
classes_override.py:89: error: Method "property1" is marked as an override, but no base method was found with this name [misc]
"""
conformance_automated = "Pass"
conformance_automated = "Fail"
errors_diff = """
Lines 134, 135: Expected error (tag 'init')
Lines 137, 138: Expected error (tag 'new')
"""
9 changes: 8 additions & 1 deletion conformance/results/pycroscope/classes_override.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
conformance_automated = "Pass"
conformant = "Partial"
notes = """
Does not honor `@override` compatibility checks for `__init__` and `__new__`:
the incompatible constructor overrides in `ChildC2` are not flagged.
"""
conformance_automated = "Fail"
errors_diff = """
Lines 134, 135: Expected error (tag 'init')
Lines 137, 138: Expected error (tag 'new')
"""
output = """
./classes_override.py:53:4: Method does not override any base method [override_does_not_override]
Expand Down
2 changes: 2 additions & 0 deletions conformance/results/pyrefly/classes_override.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ ERROR classes_override.py:57:9-16: Class member `ChildA.method4` is marked as an
ERROR classes_override.py:79:9-23: Class member `ChildA.static_method1` is marked as an override, but no parent class has a matching attribute [bad-override]
ERROR classes_override.py:84:9-22: Class member `ChildA.class_method1` is marked as an override, but no parent class has a matching attribute [bad-override]
ERROR classes_override.py:89:9-18: Class member `ChildA.property1` is marked as an override, but no parent class has a matching attribute [bad-override]
ERROR classes_override.py:135:9-17: Class member `ChildC2.__init__` overrides parent class `ParentC` in an inconsistent manner [bad-override]
ERROR classes_override.py:138:9-16: Class member `ChildC2.__new__` overrides parent class `ParentC` in an inconsistent manner [bad-override]
"""
10 changes: 8 additions & 2 deletions conformance/results/pyright/classes_override.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
conformant = "Pass"
conformant = "Partial"
notes = """
Does not honor `@override` compatibility checks for `__init__` and `__new__`:
the incompatible constructor overrides in `ChildC2` are not flagged.
"""
output = """
classes_override.py:53:9 - error: Method "method3" is marked as override, but no base method of same name is present (reportGeneralTypeIssues)
classes_override.py:65:9 - error: Method "method4" is marked as override, but no base method of same name is present (reportGeneralTypeIssues)
classes_override.py:79:9 - error: Method "static_method1" is marked as override, but no base method of same name is present (reportGeneralTypeIssues)
classes_override.py:84:9 - error: Method "class_method1" is marked as override, but no base method of same name is present (reportGeneralTypeIssues)
classes_override.py:89:9 - error: Method "property1" is marked as override, but no base method of same name is present (reportGeneralTypeIssues)
"""
conformance_automated = "Pass"
conformance_automated = "Fail"
errors_diff = """
Lines 134, 135: Expected error (tag 'init')
Lines 137, 138: Expected error (tag 'new')
"""
10 changes: 5 additions & 5 deletions conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ <h3>Python Type System Conformance Test Results</h3>
<th class="column col2 conformant">Pass</th>
</tr>
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;classes_override</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not honor `@override` compatibility checks for `__init__` and `__new__`:</p><p>the incompatible constructor overrides in `ChildC2` are not flagged.</p></span></div></th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not honor `@override` compatibility checks for `__init__` and `__new__`:</p><p>the incompatible constructor overrides in `ChildC2` are not flagged.</p></span></div></th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not honor `@override` compatibility checks for `__init__` and `__new__`:</p><p>the incompatible constructor overrides in `ChildC2` are not flagged.</p></span></div></th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 conformant">Pass</th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not honor `@override` compatibility checks for `__init__` and `__new__`:</p><p>the incompatible constructor overrides in `ChildC2` are not flagged.</p></span></div></th>
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not honor `@override` compatibility checks for `__init__` and `__new__`:</p><p>the incompatible constructor overrides in `ChildC2` are not flagged.</p></span></div></th>
</tr>
<tr><th class="column" colspan="7">
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/aliases.html">Type aliases</a>
Expand Down
9 changes: 8 additions & 1 deletion conformance/results/ty/classes_override.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
conformance_automated = "Pass"
conformant = "Partial"
notes = """
Does not honor `@override` compatibility checks for `__init__` and `__new__`:
the incompatible constructor overrides in `ChildC2` are not flagged.
"""
conformance_automated = "Fail"
errors_diff = """
Lines 134, 135: Expected error (tag 'init')
Lines 137, 138: Expected error (tag 'new')
"""
output = """
classes_override.py:53:9: error[invalid-explicit-override] Method `method3` is decorated with `@override` but does not override anything
Expand Down
9 changes: 8 additions & 1 deletion conformance/results/zuban/classes_override.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
conformance_automated = "Pass"
conformant = "Partial"
notes = """
Does not honor `@override` compatibility checks for `__init__` and `__new__`:
the incompatible constructor overrides in `ChildC2` are not flagged.
"""
conformance_automated = "Fail"
errors_diff = """
Lines 134, 135: Expected error (tag 'init')
Lines 137, 138: Expected error (tag 'new')
"""
output = """
classes_override.py:53: error: Method "method3" is marked as an override, but no base method was found with this name [misc]
Expand Down
48 changes: 48 additions & 0 deletions conformance/tests/classes_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,51 @@ class ChildB(ParentB):
@override
def method1(self) -> None: # OK
pass


# > When type checkers encounter a method decorated with @typing.override they
# > should treat it as a type error unless that method is overriding a method or
# > attribute in some ancestor class, and the type of the overriding method is
# > assignable to the type of the overridden method.

# ``__init__`` and ``__new__`` are normally exempt from override compatibility
# checks, since constructors are not subject to the Liskov substitution
# principle. However, when they are explicitly decorated with ``@override`` the
# decorator's assignability check should still be honored.
# See https://github.com/python/typing/issues/2222


class ParentC:
def __init__(self, x: int) -> None: ...

def __new__(cls, x: int) -> "ParentC":
raise NotImplementedError


class ChildC1(ParentC):
@override
def __init__(self, x: int) -> None: ... # OK

@override
def __new__(cls, x: int) -> "ChildC1": # OK
raise NotImplementedError


class ChildC2(ParentC):
@override # E[init]
def __init__(self, x: str) -> None: ... # E[init]: not assignable to "ParentC.__init__"

@override # E[new]
def __new__(cls, x: str) -> "ChildC2": # E[new]: not assignable to "ParentC.__new__"
raise NotImplementedError


# Without ``@override`` an incompatible constructor signature is allowed, since
# ``__init__`` and ``__new__`` are exempt from the usual override checks.


class ChildC3(ParentC):
def __init__(self, x: str) -> None: ... # OK

def __new__(cls, x: str) -> "ChildC3": # OK
raise NotImplementedError