Skip to content

Commit c582627

Browse files
PEP 698: Tighten up the section about typing rules. (#2969)
In our original draft to PEP 698, we wanted to emphasize that the PEP exclusively deals with `@override`, rather than adding new rules about override type signature. We did this by stating that compatibility rules were pre-existing. This is true de-facto, because all type checkers implement at least some compatibility checks, but upon a careful re-reading it turns out compatibility checks on subclass methods are not specified in any PEP. As a result, we should simply state that this PEP is not adding any new rules on signatures, without alluding to type checking rules that are not specified in previous PEPs. I will separately start a discussion in typing-sig about whether we want to provide a paper trail in PEPs - either a new PEP or a light amendment to PEP 484 - to make compatibility checks explicit. Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent d525d4d commit c582627

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

pep-0698.rst

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,13 @@ considers a method to be a valid override, which typically includes not only
205205
normal methods but also ``@property``, ``@staticmethod``, and ``@classmethod``.
206206

207207

208-
Override Compatibility Rules are Unchanged
209-
------------------------------------------
210-
211-
Type checkers already enforce compatibility rules for overrides; for example, a
212-
subclass method’s type signature should be compatible with that of the
213-
superclass method. These compatibility rules do not change due to the presence
214-
or absence of ``@override``.
215-
216-
Note that when a ``@property`` overrides a regular attribute of the base class,
217-
this should not be considered an error due to the use of ``@override``, but the
218-
type checker may still consider the override to be incompatible. For example a
219-
type checker may consider it illegal to override a non-final attribute with a
220-
getter property and no setter, as this does not respect the substitution
221-
principle.
208+
No New Rules for Override Compatibility
209+
---------------------------------------
210+
211+
This PEP is exclusively concerned with the handling of the new ``@override`` decorator,
212+
which specifies that the decorated method must override some attribute in
213+
an ancestor class. This PEP does not propose any new rules regarding the type
214+
signatures of such methods.
222215

223216

224217
Strict Enforcement Per-Project

0 commit comments

Comments
 (0)