PEP 673: Fix a couple of typos (#2419)

* Name this protocol to match usage

It would have been possible here to change the bound of the TypeVar
on line 495 to 'Shape', however I've opted to change the names of
the definitions so that they match the later (similar) definitions
of this protocol.

* Fix example generic class name

I'm guessing this was just a copy/pasta error or similar; there is
no generic class named 'Foo' which is in scope here, however there
is a 'Bar' that has just been defined and isn't yet used.
This commit is contained in:
Peter Law 2022-03-12 01:03:00 +00:00 committed by GitHub
parent b8850a417b
commit 37351ae82d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -479,7 +479,7 @@ Use in Protocols
from typing import Protocol, Self
class Shape(Protocol):
class ShapeProtocol(Protocol):
scale: float
def set_scale(self, scale: float) -> Self:
@ -494,7 +494,7 @@ is treated equivalently to:
SelfShape = TypeVar("SelfShape", bound="ShapeProtocol")
class Shape(Protocol):
class ShapeProtocol(Protocol):
scale: float
def set_scale(self: SelfShape, scale: float) -> SelfShape:
@ -658,7 +658,7 @@ The following uses of ``Self`` are rejected.
class Bar(Generic[T]):
def bar(self) -> T: ...
class Baz(Foo[Self]): ... # Rejected
class Baz(Bar[Self]): ... # Rejected
We reject type aliases containing ``Self``. Supporting ``Self``
outside class definitions can require a lot of special-handling in