[Python-checkins] peps: Edits by Ivan Levkivskyi to be more precise about types vs. classes.
guido.van.rossum
python-checkins at python.org
Fri May 6 19:07:26 EDT 2016
https://hg.python.org/peps/rev/6836e79adbc3
changeset: 6312:6836e79adbc3
user: Guido van Rossum <guido at python.org>
date: Fri May 06 16:06:56 2016 -0700
summary:
Edits by Ivan Levkivskyi to be more precise about types vs. classes.
From https://github.com/python/typing/pull/214.
files:
pep-0484.txt | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/pep-0484.txt b/pep-0484.txt
--- a/pep-0484.txt
+++ b/pep-0484.txt
@@ -587,7 +587,7 @@
A type variable may specify an upper bound using ``bound=<type>``.
This means that an actual type substituted (explicitly or implictly)
-for the type variable must be a subclass of the boundary type. A
+for the type variable must be a subtype of the boundary type. A
common example is the definition of a Comparable type that works well
enough to catch the most common errors::
@@ -618,7 +618,7 @@
An upper bound cannot be combined with type constraints (as in used
``AnyStr``, see the example earlier); type constraints cause the
inferred type to be _exactly_ one of the constraint types, while an
-upper bound just requires that the actual type is a subclass of the
+upper bound just requires that the actual type is a subtype of the
boundary type.
@@ -819,9 +819,10 @@
e = [e]
...
-A type factored by ``Union[T1, T2, ...]`` responds ``True`` to
-``issubclass`` checks for ``T1`` and any of its subtypes, ``T2`` and
-any of its subtypes, and so on.
+A type factored by ``Union[T1, T2, ...]`` is a supertype
+of all types ``T1``, ``T2``, etc., so that a value that
+is a member of one of these types is acceptable for an argument
+annotated by ``Union[T1, T2, ...]``.
One common case of union types are *optional* types. By default,
``None`` is an invalid value for any type, unless a default value of
@@ -1294,6 +1295,12 @@
collection ABCs (e.g. ``Sequence``), and a small collection of
convenience definitions.
+Note that special type constructs, such as ``Any``, ``Union``,
+and type variables defined using ``TypeVar`` are only supported
+in the type annotation context, and ``Generic`` may only be used
+as a base class. All of these will raise ``TypeError`` if appear
+in ``isinstance`` or ``issubclass``.
+
Fundamental building blocks:
* Any, used as ``def get(key: str) -> Any: ...``
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list