Skip to content

Commit e7cba09

Browse files
committed
spec: various minor changes
- Replace an incorrect use of "subtype" with "assignable" - Remove discussion of str/bytes Literal types that seems geared towards Python 2. Instead, say straightforwardly that strings (str objects) and bytes objects are supported. - Rewrite an example that relies on the int/float/complex special case. The example was correct but I think it's confusing to readers if we have examples unnecessarily rely on the special case. Instead, use example types with more straightforward behavior.
1 parent ef75648 commit e7cba09

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

docs/spec/generics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ Bound Rules
20002000
T1 = TypeVar("T1", bound=int)
20012001
TypeVar("Ok", default=T1, bound=float) # Valid
20022002
TypeVar("AlsoOk", default=T1, bound=int) # Valid
2003-
TypeVar("Invalid", default=T1, bound=str) # Invalid: int is not a subtype of str
2003+
TypeVar("Invalid", default=T1, bound=str) # Invalid: int is not assignable to str
20042004

20052005
Constraint Rules
20062006
^^^^^^^^^^^^^^^^

docs/spec/literal.rst

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ expressions, and nothing else.
9898
Legal parameters for ``Literal`` at type check time
9999
"""""""""""""""""""""""""""""""""""""""""""""""""""
100100

101-
``Literal`` may be parameterized with literal ints, byte and unicode strings,
101+
``Literal`` may be parameterized with literal ints, strings, `bytes` objects,
102102
bools, Enum values and ``None``. So for example, all of
103103
the following would be legal::
104104

105105
Literal[26]
106106
Literal[0x1A] # Exactly equivalent to Literal[26]
107107
Literal[-4]
108108
Literal["hello world"]
109+
Literal[u"hello world"] # Exactly equivalent to Literal["hello world"]
109110
Literal[b"hello world"]
110-
Literal[u"hello world"]
111111
Literal[True]
112112
Literal[Color.RED] # Assuming Color is some enum
113113
Literal[None]
@@ -143,17 +143,6 @@ This should be exactly equivalent to the following type::
143143

144144
Literal[1, 2, 3, "foo", 5] | None
145145

146-
**Note:** String literal types like ``Literal["foo"]`` should subtype either
147-
bytes or unicode in the same way regular string literals do at runtime.
148-
149-
For example, in Python 3, the type ``Literal["foo"]`` is equivalent to
150-
``Literal[u"foo"]``, since ``"foo"`` is equivalent to ``u"foo"`` in Python 3.
151-
152-
Similarly, in Python 2, the type ``Literal["foo"]`` is equivalent to
153-
``Literal[b"foo"]`` -- unless the file includes a
154-
``from __future__ import unicode_literals`` import, in which case it would be
155-
equivalent to ``Literal[u"foo"]``.
156-
157146
Illegal parameters for ``Literal`` at type check time
158147
"""""""""""""""""""""""""""""""""""""""""""""""""""""
159148

docs/spec/tuples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Type Compatibility Rules
9191
------------------------
9292

9393
Because tuple contents are immutable, the element types of a tuple are covariant.
94-
For example, ``tuple[int, int]`` is a subtype of ``tuple[float, complex]``.
94+
For example, ``tuple[bool, int]`` is a subtype of ``tuple[int, object]``.
9595

9696
As discussed above, a homogeneous tuple of arbitrary length is equivalent
9797
to a union of tuples of different lengths. That means ``tuple[()]``,

0 commit comments

Comments
 (0)