GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Add typing.override decorator · Issue #101561 · python/cpython Closed Labels 3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement DescriptionFeature or enhancementSee PEP 698 for details. The PitchThe purpose of To quote the PEP consider a code change where we rename a parent class method. The original code looks like this: class Parent: def foo(self, x: int) -> int: return x class Child(Parent): def foo(self, x: int) -> int: return x + 1 def parent_callsite(parent: Parent) -> None: parent.foo(1) def child_callsite(child: Child) -> None: child.foo(1) And after our rename it looks like this: class Parent: # Rename this method def new_foo(self, x: int) -> int: return x class Child(Parent): # This (unchanged) method used to override `foo` but is unrelated to `new_foo` def foo(self, x: int) -> int: return x + 1 def parent_callsite(parent: Parent) -> None: # If we pass a Child instance we’ll now run Parent.new_foo - likely a bug parent.new_foo(1) def child_callsite(child: Child) -> None: # We probably wanted to invoke new_foo here. Instead, we forked the method child.foo(1) In the code snippet above, renaming If we mark from typing import override class Parent: def new_foo(self) -> int: return 1 def bar(self, x: str) -> str: return x class Child(Parent): @override def foo(self) -> int: # Type Error: foo does not override an attribute of any ancestor return 2 Previous discussionPEP 698 has details about the proposal itself. Discussion on this proposal has happened on typing-sig and on [discuss.python.org)[https://discuss.python.org/t/pep-698-a-typing-override-decorator/20839]. Linked PRsReacted by qzhang Reacted by Alex Waygood and Younghoon YUN Reacted by qzhang Activity
MetadataMetadataAssigneesLabels3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |