Skip to content

Commit

Permalink
PEP 673: Fix a couple of typos (#2419)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
PeterJCLaw authored Mar 12, 2022
1 parent b8850a4 commit 37351ae
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pep-0673.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 37351ae

Please sign in to comment.