diff options
author | Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com> | 2019-12-30 16:08:08 (GMT) |
---|---|---|
committer | Ivan Levkivskyi <levkivskyi@gmail.com> | 2019-12-30 16:08:08 (GMT) |
commit | 09c482fad11c769be38b2449f1056e264b701bb7 (patch) | |
tree | 02da3aca6aa3c39e08d20b1f9417af7cb42bfed0 /Lib/tempfile.py | |
parent | 4dc5a9df59837446ec1dc5b7a0e6ce95ae5b5cec (diff) | |
download | cpython-09c482fad11c769be38b2449f1056e264b701bb7.zip cpython-09c482fad11c769be38b2449f1056e264b701bb7.tar.gz cpython-09c482fad11c769be38b2449f1056e264b701bb7.tar.bz2 |
bpo-39019: Implement missing __class_getitem__ for SpooledTemporaryFile (GH-17560)
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r-- | Lib/tempfile.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 6287554..448163f 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -643,6 +643,18 @@ 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 + def _check(self, file): if self._rolled: return max_size = self._max_size |