Skip to content

Commit af366c0

Browse files
authored
Explain generic Protocol[T1, T2, ...] shorthand in Mypy docs (python#12047)
As far as I can tell, the nugget exposed by this commit lives only in PEP 544. This copies that nugget closer to where it is likely to be spotted by the intended audience. PEPs may not be accessible to customers who reasonably expect relevant information to be surfaced in featured documentation. Even if customers are aware of PEPs, they may not think to look there, and don't likely consider them primary sources. It is reasonable to assume that is the job of the docs, with PEPs capturing more esoteric nuances, rationales and other then-relevant details of decision-making, etc. It's also reasonable to expect that where further study may be helpful, links from relevant sections of primary sources to secondary materials like PEPs should exist. This commit fills in both gaps for the subject shorthand.
1 parent 619d9bd commit af366c0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

docs/source/generics.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ protocols mostly follow the normal rules for generic classes. Example:
673673
y: Box[int] = ...
674674
x = y # Error -- Box is invariant
675675
676+
Per :pep:`PEP 544: Generic protocols <544#generic-protocols>`, ``class
677+
ClassName(Protocol[T])`` is allowed as a shorthand for ``class
678+
ClassName(Protocol, Generic[T])``.
679+
676680
The main difference between generic protocols and ordinary generic
677681
classes is that mypy checks that the declared variances of generic
678682
type variables in a protocol match how they are used in the protocol

0 commit comments

Comments
 (0)