10000 bpo-39481: PEP 585 for a variety of modules by isidentical · Pull Request #19423 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-39481: PEP 585 for a variety of modules #19423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading < 10000 /div>
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Append group 2
  • Loading branch information
isidentical committed Apr 10, 2020
commit c97c44ddc0a4ce1ff067ed08bf4fc8b8bacdb6b2
3 changes: 3 additions & 0 deletions Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -450,6 +451,8 @@ def __getitem__(self, name):
def LoadLibrary(self, name):
return self._dlltype(name)

__class_getitem__ = classmethod(_types.GenericAlias)

cdll = LibraryLoader(CDLL)
pydll = LibraryLoader(PyDLL)

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_genericalias.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
from collections.abc import *
from contextlib import AbstractContextManager, AbstractAsyncContextManager
from ctypes import Array, LibraryLoader
from difflib import SequenceMatcher
from filecmp import dircmp
from fileinput import FileInput
Expand All @@ -17,6 +18,7 @@
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
Expand Down Expand Up @@ -55,6 +57,8 @@ def test_subscriptable(self):
TemporaryDirectory, SpooledTemporaryFile,
Queue, SimpleQueue,
_AssertRaisesContext,
Array, LibraryLoader,
SplitResult, ParseResult,
):
tname = t.__name__
with self.subTest(f"Testing {tname}"):
Expand Down
3 changes: 3 additions & 0 deletions Lib/urllib/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import re
import sys
import types
import collections
import warnings

Expand Down Expand Up @@ -176,6 +177,8 @@ def port(self):
raise ValueError("Port out of range 0-65535")
return port

__class_getitem__ = classmethod(types.GenericAlias)


class _NetlocResultMixinStr(_NetlocResultMixinBase, _ResultMixinStr):
__slots__ = ()
Expand Down
8 changes: 7 additions & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; */
Expand Down Expand Up @@ -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 */
Expand Down
0