Skip to content
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

bpo-39481: Make functools.cached_property, partial, ... #19427

Merged
merged 4 commits into from
Apr 14, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# import types, weakref # Deferred to single_dispatch()
from reprlib import recursive_repr
from _thread import RLock
from types import GenericAlias


################################################################################
Expand Down Expand Up @@ -656,6 +657,9 @@ def __get__(self, obj, cls=None):
def __isabstractmethod__(self):
return getattr(self.func, "__isabstractmethod__", False)

__class_getitem__ = classmethod(GenericAlias)


# Helper functions

def _unwrap_partial(func):
Expand Down Expand Up @@ -1208,3 +1212,5 @@ def __get__(self, instance, owner=None):
)
raise TypeError(msg) from None
return val

__class_getitem__ = classmethod(GenericAlias)
2 changes: 2 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 functools import partial, partialmethod, _lru_cache_wrapper, cached_property
from os import DirEntry
from re import Pattern, Match
from types import GenericAlias, MappingProxyType
Expand All @@ -23,6 +24,7 @@ def test_subscriptable(self):
defaultdict, deque,
OrderedDict, Counter, UserDict, UserList,
Pattern, Match,
partial, partialmethod, _lru_cache_wrapper, cached_property,
AbstractContextManager, AbstractAsyncContextManager,
Awaitable, Coroutine,
AsyncIterable, AsyncIterator,
Expand Down
4 changes: 4 additions & 0 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ partial_setstate(partialobject *pto, PyObject *state)
static PyMethodDef partial_methods[] = {
{"__reduce__", (PyCFunction)partial_reduce, METH_NOARGS},
{"__setstate__", (PyCFunction)partial_setstate, METH_O},
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{NULL, NULL} /* sentinel */
};

Expand Down Expand Up @@ -1346,6 +1348,8 @@ static PyMethodDef lru_cache_methods[] = {
{"__reduce__", (PyCFunction)lru_cache_reduce, METH_NOARGS},
{"__copy__", (PyCFunction)lru_cache_copy, METH_VARARGS},
{"__deepcopy__", (PyCFunction)lru_cache_deepcopy, METH_VARARGS},
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{NULL}
};

Expand Down