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