PEP 698: Add "self" parameters to methods and a colon to a class (#3490)

This commit is contained in:
Mikhail Golubev 2023-10-18 09:06:41 +03:00 committed by GitHub
parent fb526a8822
commit ad131c6132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -196,7 +196,7 @@ method or attribute in some ancestor class.
return 2
@override
def baz() -> int: # Type check error: no matching signature in ancestor
def baz(self) -> int: # Type check error: no matching signature in ancestor
return 1
@ -240,7 +240,7 @@ Consider the following code:
pass
class Child(Parent):
def foo() -> int:
def foo(self) -> int:
return 2
Imagine we refactor it as follows:
@ -248,12 +248,12 @@ Imagine we refactor it as follows:
.. code-block:: python
class Parent
def foo() -> int: # This method is new
class Parent:
def foo(self) -> int: # This method is new
return 1
class Child(Parent):
def foo() -> int: # This is now an override!
def foo(self) -> int: # This is now an override!
return 2
def call_foo(parent: Parent) -> int:
@ -416,22 +416,22 @@ ancestor class where the overridden method should be defined:
.. code-block:: python
class Parent0:
def foo() -> int:
def foo(self) -> int:
return 1
class Parent1:
def bar() -> int:
def bar(self) -> int:
return 1
class Child(Parent0, Parent1):
@override(Parent0) # okay, Parent0 defines foo
def foo() -> int:
def foo(self) -> int:
return 2
@override(Parent0) # type error, Parent0 does not define bar
def bar() -> int:
def bar(self) -> int:
return 2