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