Skip to content

Commit c1dc44b

Browse files
ilevkivskyigvanrossum
authored andcommitted
Updates for PEPs 484 and 483 (#111)
1 parent 202e674 commit c1dc44b

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

pep-0483.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,16 @@ defined by three rules:
184184
subtype of ``t2``. (But not the other way around.)
185185
- ``Any`` is consistent with every type. (But ``Any`` is not a subtype
186186
of every type.)
187-
- Every type is a subtype of ``Any``. (Which also makes every type
188-
consistent with ``Any``, via rule 1.)
187+
- Every type is consistent with ``Any``. (But every type is not a subtype
188+
of ``Any``.)
189189

190190
That's all! See Jeremy Siek's blog post `What is Gradual
191191
Typing <http://wphomes.soic.indiana.edu/jsiek/what-is-gradual-typing/>`_
192-
for a longer explanation and motivation. Note that rule 3 places ``Any``
193-
at the root of the type graph. This makes it very similar to
194-
``object``. The difference is that ``object`` is not consistent with
192+
for a longer explanation and motivation. ``Any`` can be considered a type
193+
that has all values and all methods. Combined with the definition of
194+
subtyping above, this places ``Any`` partially at the top (it has all values)
195+
and bottom (it has all methods) of the type hierarchy. Contrast this to
196+
``object`` -- it is not consistent with
195197
most types (e.g. you can't use an ``object()`` instance where an
196198
``int`` is expected). IOW both ``Any`` and ``object`` mean
197199
"any type is allowed" when used to annotate an argument, but only ``Any``
@@ -269,14 +271,14 @@ between classes and types the following general rules apply:
269271
- No types defined below can be subclassed, except for ``Generic`` and
270272
classes derived from it.
271273
- All of these will raise ``TypeError`` if they appear
272-
in ``isinstance`` or ``issubclass``.
274+
in ``isinstance`` or ``issubclass`` (except for unparametrized generics).
273275

274276

275277
Fundamental building blocks
276278
---------------------------
277279

278-
- **Any**. Every type is a subtype of ``Any``; however, to the static
279-
type checker it is also consistent with every type (see above).
280+
- **Any**. Every type is consistent with ``Any``; and
281+
it is also consistent with every type (see above).
280282
- **Union[t1, t2, ...]**. Types that are subtype of at least one of
281283
``t1`` etc. are subtypes of this.
282284

@@ -292,9 +294,7 @@ Fundamental building blocks
292294
Example: ``Union[Employee, Manager] == Union[Employee]``.
293295
* ``Union[t1]`` returns just ``t1``. ``Union[]`` is illegal,
294296
so is ``Union[()]``
295-
* Corollary: ``Union[..., Any, ...]`` returns ``Any``;
296-
``Union[..., object, ...]`` returns ``object``; to cut a
297-
tie, ``Union[Any, object] == Union[object, Any] == Any``.
297+
* Corollary: ``Union[..., object, ...]`` returns ``object``.
298298

299299
- **Optional[t1]**. Alias for ``Union[t1, None]``, i.e. ``Union[t1,
300300
type(None)]``.

pep-0484.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,9 @@ one value::
10081008
The ``Any`` type
10091009
----------------
10101010

1011-
A special kind of type is ``Any``. Every type is a subtype of
1012-
``Any``. This is also true for the builtin type ``object``.
1013-
However, to the static type checker these are completely different.
1011+
A special kind of type is ``Any``. Every type is consistent with
1012+
``Any``. It can be considered a type that has all values and all methods.
1013+
Note that ``Any`` and builtin type ``object`` are completely different.
10141014

10151015
When the type of a value is ``object``, the type checker will reject
10161016
almost all operations on it, and assigning it to a variable (or using
@@ -1705,8 +1705,8 @@ convenience definitions.
17051705
Note that special type constructs, such as ``Any``, ``Union``,
17061706
and type variables defined using ``TypeVar`` are only supported
17071707
in the type annotation context, and ``Generic`` may only be used
1708-
as a base class. All of these will raise ``TypeError`` if appear
1709-
in ``isinstance`` or ``issubclass``.
1708+
as a base class. All of these (except for unparameterized generics)
1709+
will raise ``TypeError`` if appear in ``isinstance`` or ``issubclass``.
17101710

17111711
Fundamental building blocks:
17121712

0 commit comments

Comments
 (0)