summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBatuhan Taşkaya <batuhanosmantaskaya@gmail.com>2020-04-10 14:46:36 (GMT)
committerGitHub <noreply@github.com>2020-04-10 14:46:36 (GMT)
commit0361556537686f857f1025ead75e6af4ca7cc94a (patch)
tree3cce4f12e341d4266d1308f94a92a7c4b25bcdf9 /Lib
parente3ec44d692d9442e640cf5b2d8708157a65cec3e (diff)
downloadcpython-0361556537686f857f1025ead75e6af4ca7cc94a.zip
cpython-0361556537686f857f1025ead75e6af4ca7cc94a.tar.gz
cpython-0361556537686f857f1025ead75e6af4ca7cc94a.tar.bz2
bpo-39481: PEP 585 for a variety of modules (GH-19423)
- concurrent.futures - ctypes - http.cookies - multiprocessing - queue - tempfile - unittest.case - urllib.parse
Diffstat (limited to 'Lib')
-rw-r--r--Lib/concurrent/futures/_base.py3
-rw-r--r--Lib/concurrent/futures/thread.py3
-rw-r--r--Lib/ctypes/__init__.py3
-rw-r--r--Lib/http/cookies.py3
-rw-r--r--Lib/multiprocessing/managers.py3
-rw-r--r--Lib/multiprocessing/pool.py3
-rw-r--r--Lib/multiprocessing/queues.py3
-rw-r--r--Lib/multiprocessing/shared_memory.py3
-rw-r--r--Lib/queue.py5
-rw-r--r--Lib/tempfile.py2
-rw-r--r--Lib/test/test_genericalias.py21
-rw-r--r--Lib/unittest/case.py2
-rw-r--r--Lib/urllib/parse.py3
13 files changed, 57 insertions, 0 deletions
diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py
index fd0acec..bf546f8 100644
--- a/Lib/concurrent/futures/_base.py
+++ b/Lib/concurrent/futures/_base.py
@@ -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."""
diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py
index 2aa4e17..2810b35 100644
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -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:
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
index 8f09911..4afa4eb 100644
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -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)
diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py
index 6694f54..35ac2dc 100644
--- a/Lib/http/cookies.py
+++ b/Lib/http/cookies.py
@@ -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
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index 1668220..9d490a1 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -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__',
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index 41dd923..b8a0b82 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -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
#
diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py
index d112db2..8350701 100644
--- a/Lib/multiprocessing/queues.py
+++ b/Lib/multiprocessing/queues.py
@@ -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)
diff --git a/Lib/multiprocessing/shared_memory.py b/Lib/multiprocessing/shared_memory.py
index 184e367..9f954d9 100644
--- a/Lib/multiprocessing/shared_memory.py
+++ b/Lib/multiprocessing/shared_memory.py
@@ -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)
diff --git a/Lib/queue.py b/Lib/queue.py
index 5bb0431..10dbcbc 100644
--- a/Lib/queue.py
+++ b/Lib/queue.py
@@ -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
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index a398345..ed15c0f 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -829,3 +829,5 @@ class TemporaryDirectory(object):
def cleanup(self):
if self._finalizer.detach():
self._rmtree(self.name)
+
+ __class_getitem__ = classmethod(_types.GenericAlias)
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 4241eab..a00899f 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -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}"):
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 5e5d535..d0ee561 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -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."""
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index 779278b..ea897c3 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -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__ = ()