diff --git a/pep-0544.txt b/pep-0544.txt index e8023ae11..079a55354 100644 --- a/pep-0544.txt +++ b/pep-0544.txt @@ -586,6 +586,30 @@ Continuing the previous example:: walk(tree) # OK, 'Tree[float]' is a subtype of 'Traversable' +Self-types in protocols +----------------------- + +The self-types in protocols follow the corresponding specification +[self-types]_ of PEP 484. For example:: + + C = TypeVar('C', bound='Copyable') + class Copyable(Protocol): + def copy(self: C) -> C: + + class One: + def copy(self) -> 'One': + ... + + T = TypeVar('T', bound='Other') + class Other: + def copy(self: T) -> T: + ... + + c: Copyable + c = One() # OK + c = Other() # Also OK + + Using Protocols =============== @@ -1369,6 +1393,9 @@ References .. [elsewhere] https://github.com/python/peps/pull/224 +.. [self-types] + https://www.python.org/dev/peps/pep-0484/#annotating-instance-and-class-methods + Copyright =========