summaryrefslogtreecommitdiffstats
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2020-04-07 16:50:06 (GMT)
committerGitHub <noreply@github.com>2020-04-07 16:50:06 (GMT)
commit48b069a003ba6c684a9ba78493fbbec5e89f10b8 (patch)
treee67e71abd17516cea5fe1a1ec487bf929ab0b9fd /Lib/tempfile.py
parent9cc3ebd7e04cb645ac7b2f372eaafa7464e16b9c (diff)
downloadcpython-48b069a003ba6c684a9ba78493fbbec5e89f10b8.zip
cpython-48b069a003ba6c684a9ba78493fbbec5e89f10b8.tar.gz
cpython-48b069a003ba6c684a9ba78493fbbec5e89f10b8.tar.bz2
bpo-39481: Implementation for PEP 585 (#18239)
This implements things like `list[int]`, which returns an object of type `types.GenericAlias`. This object mostly acts as a proxy for `list`, but has attributes `__origin__` and `__args__` that allow recovering the parts (with values `list` and `(int,)`. There is also an approximate notion of type variables; e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`. Type variables are objects of type `typing.TypeVar`.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r--Lib/tempfile.py13
1 files changed, 2 insertions, 11 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index b27165b..a398345 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -44,6 +44,7 @@ import shutil as _shutil
import errno as _errno
from random import Random as _Random
import sys as _sys
+import types as _types
import weakref as _weakref
import _thread
_allocate_lock = _thread.allocate_lock
@@ -643,17 +644,7 @@ class SpooledTemporaryFile:
'encoding': encoding, 'newline': newline,
'dir': dir, 'errors': errors}
- def __class_getitem__(cls, type):
- """Provide minimal support for using this class as generic
- (for example in type annotations).
-
- See PEP 484 and PEP 560 for more details. For example,
- `SpooledTemporaryFile[str]` is a valid expression at runtime (type
- argument `str` indicates whether the file is open in bytes or text
- mode). Note, no type checking happens at runtime, but a static type
- checker can be used.
- """
- return cls
+ __class_getitem__ = classmethod(_types.GenericAlias)
def _check(self, file):
if self._rolled: return