]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39481: PEP 585 for a variety of modules (GH-19423)
authorBatuhan Taşkaya <batuhanosmantaskaya@gmail.com>
Fri, 10 Apr 2020 14:46:36 +0000 (17:46 +0300)
committerGitHub <noreply@github.com>
Fri, 10 Apr 2020 14:46:36 +0000 (07:46 -0700)
- concurrent.futures
- ctypes
- http.cookies
- multiprocessing
- queue
- tempfile
- unittest.case
- urllib.parse

15 files changed:
Lib/concurrent/futures/_base.py
Lib/concurrent/futures/thread.py
Lib/ctypes/__init__.py
Lib/http/cookies.py
Lib/multiprocessing/managers.py
Lib/multiprocessing/pool.py
Lib/multiprocessing/queues.py
Lib/multiprocessing/shared_memory.py
Lib/queue.py
Lib/tempfile.py
Lib/test/test_genericalias.py
Lib/unittest/case.py
Lib/urllib/parse.py
Modules/_ctypes/_ctypes.c
Modules/_queuemodule.c

index fd0acec55d0460a94ad0692ca73890fbaa779ff8..bf546f8ae1d1cc92f346f6de0842108e178f70a1 100644 (file)
@@ -7,6 +7,7 @@ import collections
 import logging
 import threading
 import time
+import types
 
 FIRST_COMPLETED = 'FIRST_COMPLETED'
 FIRST_EXCEPTION = 'FIRST_EXCEPTION'
@@ -544,6 +545,8 @@ class Future(object):
             self._condition.notify_all()
         self._invoke_callbacks()
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 class Executor(object):
     """This is an abstract base class for concrete asynchronous executors."""
 
index 2aa4e17d47fa7c3e11461d310fc933c593982d7c..2810b357bc1e17daa78129e427514463c5afded5 100644 (file)
@@ -10,6 +10,7 @@ from concurrent.futures import _base
 import itertools
 import queue
 import threading
+import types
 import weakref
 import os
 
@@ -57,6 +58,8 @@ class _WorkItem(object):
         else:
             self.future.set_result(result)
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 
 def _worker(executor_reference, work_queue, initializer, initargs):
     if initializer is not None:
index 8f0991147d72f20488fd28afbbe12085e574da71..4afa4ebd4224934904e3817d91dcbb45722a7c5a 100644 (file)
@@ -1,6 +1,7 @@
 """create and manipulate C data types in Python"""
 
 import os as _os, sys as _sys
+import types as _types
 
 __version__ = "1.1.0"
 
@@ -450,6 +451,8 @@ class LibraryLoader(object):
     def LoadLibrary(self, name):
         return self._dlltype(name)
 
+    __class_getitem__ = classmethod(_types.GenericAlias)
+
 cdll = LibraryLoader(CDLL)
 pydll = LibraryLoader(PyDLL)
 
index 6694f5478bdadfb84ac4c5b1398ecf79123fa7b9..35ac2dc6ae280c5ff5adc817af1fbc9620041105 100644 (file)
@@ -131,6 +131,7 @@ Finis.
 #
 import re
 import string
+import types
 
 __all__ = ["CookieError", "BaseCookie", "SimpleCookie"]
 
@@ -419,6 +420,8 @@ class Morsel(dict):
         # Return the result
         return _semispacejoin(result)
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 
 #
 # Pattern for finding cookie
index 1668220c09957116158f2b5352c710ddadacfef9..9d490a1d8b3525b2967cbaee8290a97daef0d64e 100644 (file)
@@ -21,6 +21,7 @@ import signal
 import array
 import queue
 import time
+import types
 import os
 from os import getpid
 
@@ -1129,6 +1130,8 @@ class ValueProxy(BaseProxy):
         return self._callmethod('set', (value,))
     value = property(get, set)
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 
 BaseListProxy = MakeProxyType('BaseListProxy', (
     '__add__', '__contains__', '__delitem__', '__getitem__', '__len__',
index 41dd923d4f9740716ede9323556dfa133d2eef6d..b8a0b827635f07ae53d33579e674cb171eaba716 100644 (file)
@@ -20,6 +20,7 @@ import queue
 import threading
 import time
 import traceback
+import types
 import warnings
 from queue import Empty
 
@@ -780,6 +781,8 @@ class ApplyResult(object):
         del self._cache[self._job]
         self._pool = None
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 AsyncResult = ApplyResult       # create alias -- see #17805
 
 #
index d112db2cd981d116c226806ef3c84037d7b515e7..835070118387ea70a929835856c6dd0bb865bd35 100644 (file)
@@ -14,6 +14,7 @@ import os
 import threading
 import collections
 import time
+import types
 import weakref
 import errno
 
@@ -366,3 +367,5 @@ class SimpleQueue(object):
         else:
             with self._wlock:
                 self._writer.send_bytes(obj)
+
+    __class_getitem__ = classmethod(types.GenericAlias)
index 184e36704baaeba95cc36a9030a2ff819a77c2e2..9f954d9c38febdebc34d03d40d840bf0d7f60003 100644 (file)
@@ -14,6 +14,7 @@ import os
 import errno
 import struct
 import secrets
+import types
 
 if os.name == "nt":
     import _winapi
@@ -508,3 +509,5 @@ class ShareableList:
                 return position
         else:
             raise ValueError(f"{value!r} not in this container")
+
+    __class_getitem__ = classmethod(types.GenericAlias)
index 5bb0431e9494617ede7d87d153bde2e1bbe27315..10dbcbc18ece8556037ec1d360a7548fc8445c3e 100644 (file)
@@ -1,6 +1,7 @@
 '''A multi-producer, multi-consumer queue.'''
 
 import threading
+import types
 from collections import deque
 from heapq import heappush, heappop
 from time import monotonic as time
@@ -216,6 +217,8 @@ class Queue:
     def _get(self):
         return self.queue.popleft()
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 
 class PriorityQueue(Queue):
     '''Variant of Queue that retrieves open entries in priority order (lowest first).
@@ -316,6 +319,8 @@ class _PySimpleQueue:
         '''Return the approximate size of the queue (not reliable!).'''
         return len(self._queue)
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 
 if SimpleQueue is None:
     SimpleQueue = _PySimpleQueue
index a398345f108d0fff6974fb2d1c595c134030f667..ed15c0fd1f8afc055bf009328165849604eb755a 100644 (file)
@@ -829,3 +829,5 @@ class TemporaryDirectory(object):
     def cleanup(self):
         if self._finalizer.detach():
             self._rmtree(self.name)
+
+    __class_getitem__ = classmethod(_types.GenericAlias)
index 4241eabed084528c241bd1bf0861581fffc8be68..a00899f5267d724cba1d301d6f84e08211a65d14 100644 (file)
@@ -6,16 +6,28 @@ from collections import (
     defaultdict, deque, OrderedDict, Counter, UserDict, UserList
 )
 from collections.abc import *
+from concurrent.futures import Future
+from concurrent.futures.thread import _WorkItem
 from contextlib import AbstractContextManager, AbstractAsyncContextManager
+from ctypes import Array, LibraryLoader
 from difflib import SequenceMatcher
 from filecmp import dircmp
 from fileinput import FileInput
 from mmap import mmap
 from ipaddress import IPv4Network, IPv4Interface, IPv6Network, IPv6Interface
 from itertools import chain
+from http.cookies import Morsel
+from multiprocessing.managers import ValueProxy
+from multiprocessing.pool import ApplyResult
+from multiprocessing.shared_memory import ShareableList
+from multiprocessing.queues import SimpleQueue
 from os import DirEntry
 from re import Pattern, Match
 from types import GenericAlias, MappingProxyType, AsyncGeneratorType
+from tempfile import TemporaryDirectory, SpooledTemporaryFile
+from urllib.parse import SplitResult, ParseResult
+from unittest.case import _AssertRaisesContext
+from queue import Queue, SimpleQueue
 import typing
 
 from typing import TypeVar
@@ -49,6 +61,15 @@ class BaseTest(unittest.TestCase):
                   DirEntry,
                   IPv4Network, IPv4Interface, IPv6Network, IPv6Interface,
                   chain,
+                  TemporaryDirectory, SpooledTemporaryFile,
+                  Queue, SimpleQueue,
+                  _AssertRaisesContext,
+                  Array, LibraryLoader,
+                  SplitResult, ParseResult,
+                  ValueProxy, ApplyResult,
+                  ShareableList, SimpleQueue,
+                  Future, _WorkItem,
+                  Morsel,
                   ):
             tname = t.__name__
             with self.subTest(f"Testing {tname}"):
index 5e5d535dc693870f5437336d217a2c34e4b60e5e..d0ee561a3ae93a95358be9dba304237399661f33 100644 (file)
@@ -241,6 +241,8 @@ class _AssertRaisesContext(_AssertRaisesBaseContext):
                      expected_regex.pattern, str(exc_value)))
         return True
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 
 class _AssertWarnsContext(_AssertRaisesBaseContext):
     """A context manager used to implement TestCase.assertWarns* methods."""
index 779278bac598a10ed4c19b9d2441d481957910f2..ea897c3032257b290724c21c2e4c20542175b42c 100644 (file)
@@ -29,6 +29,7 @@ test_urlparse.py provides a good indicator of parsing behavior.
 
 import re
 import sys
+import types
 import collections
 import warnings
 
@@ -176,6 +177,8 @@ class _NetlocResultMixinBase(object):
                 raise ValueError("Port out of range 0-65535")
         return port
 
+    __class_getitem__ = classmethod(types.GenericAlias)
+
 
 class _NetlocResultMixinStr(_NetlocResultMixinBase, _ResultMixinStr):
     __slots__ = ()
index dab39396476ba4bafdf1b23fd772f9d2729225e8..ba5ef397cf05bf217d8068715bee4714bfe62084 100644 (file)
@@ -4798,6 +4798,12 @@ Array_length(PyObject *myself)
     return self->b_length;
 }
 
+static PyMethodDef Array_methods[] = {
+    {"__class_getitem__",    (PyCFunction)Py_GenericAlias,
+    METH_O|METH_CLASS,       PyDoc_STR("See PEP 585")},
+    { NULL, NULL }
+};
+
 static PySequenceMethods Array_as_sequence = {
     Array_length,                               /* sq_length; */
     0,                                          /* sq_concat; */
@@ -4846,7 +4852,7 @@ PyTypeObject PyCArray_Type = {
     0,                                          /* tp_weaklistoffset */
     0,                                          /* tp_iter */
     0,                                          /* tp_iternext */
-    0,                                          /* tp_methods */
+    Array_methods,                              /* tp_methods */
     0,                                          /* tp_members */
     0,                                          /* tp_getset */
     0,                                          /* tp_base */
index 5eef06252cd326f143397387c0f0c5fc9c932018..28bf8991285d82606ac02a2bcc3d9fa5d967d299 100644 (file)
@@ -302,6 +302,8 @@ static PyMethodDef simplequeue_methods[] = {
     _QUEUE_SIMPLEQUEUE_PUT_METHODDEF
     _QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF
     _QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF
+    {"__class_getitem__",    (PyCFunction)Py_GenericAlias,
+    METH_O|METH_CLASS,       PyDoc_STR("See PEP 585")},
     {NULL,           NULL}              /* sentinel */
 };