Skip to content

Commit 6604f9f

Browse files
committed
Backport some types from newer CPython versions for use in doctools.py
1 parent 2173f5e commit 6604f9f

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

doc-source/api/typing.rst

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,33 @@
33
=================================
44

55
.. automodule:: domdf_python_tools.typing
6-
:undoc-members:
6+
:autosummary-sections: Functions ;; Classes
7+
8+
.. data:: WrapperDescriptorType
9+
10+
The type of methods of some built-in data types and base classes such as
11+
:meth:`object.__init__` or :meth:`object.__lt__`.
12+
13+
.. versionadded:: 0.8.0
14+
15+
.. data:: MethodWrapperType
16+
17+
The type of *bound* methods of some built-in data types and base classes.
18+
For example it is the type of :code:`object().__str__`.
19+
20+
.. versionadded:: 0.8.0
21+
22+
23+
.. data:: MethodDescriptorType
24+
25+
The type of methods of some built-in data types such as :meth:`str.join`.
26+
27+
.. versionadded:: 0.8.0
28+
29+
30+
.. data:: ClassMethodDescriptorType
31+
32+
The type of *unbound* class methods of some built-in data types such as
33+
``dict.__dict__['fromkeys']``.
34+
35+
.. versionadded:: 0.8.0

domdf_python_tools/typing.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
# typing.py
44
"""
55
Common aliases for type hinting
6+
7+
**Data:**
8+
9+
.. csv-table::
10+
:widths: 5, 20
11+
12+
:data:`~.PathLike`, Type hint for objects that represent filesystem paths.
13+
:data:`~.AnyNumber`, Type hint for numbers.
14+
:data:`~.WrapperDescriptorType`, The type of methods of some built-in data types and base classes.
15+
:data:`~.MethodWrapperType`, The type of *bound* methods of some built-in data types and base classes.
16+
:data:`~.MethodDescriptorType`, The type of methods of some built-in data types.
17+
:data:`~.ClassMethodDescriptorType`, The type of *unbound* class methods of some built-in data types.
18+
619
"""
720
#
821
# Copyright © 2020 Dominic Davis-Foster <[email protected]>
@@ -33,7 +46,16 @@
3346
# 3rd party
3447
from typing_extensions import Protocol
3548

36-
__all__ = ["PathLike", "AnyNumber", "check_membership", "JsonLibrary"]
49+
__all__ = [
50+
"PathLike",
51+
"AnyNumber",
52+
"check_membership",
53+
"JsonLibrary",
54+
"WrapperDescriptorType",
55+
"MethodWrapperType",
56+
"MethodDescriptorType",
57+
"ClassMethodDescriptorType",
58+
]
3759

3860
#: Type hint for objects that represent filesystem paths.
3961
PathLike = Union[str, pathlib.Path, os.PathLike]
@@ -124,3 +146,29 @@ def loads(
124146
:param object_pairs_hook:
125147
:param kwds:
126148
"""
149+
150+
151+
# Backported from https://github.com/python/cpython/blob/master/Lib/types.py
152+
# Licensed under the Python Software Foundation License Version 2.
153+
# Copyright © 2001-2020 Python Software Foundation. All rights reserved.
154+
# Copyright © 2000 BeOpen.com . All rights reserved.
155+
# Copyright © 1995-2000 Corporation for National Research Initiatives . All rights reserved.
156+
# Copyright © 1991-1995 Stichting Mathematisch Centrum . All rights reserved.
157+
#
158+
159+
# if domdf_python_tools.DOCUMENTING:
160+
# WrapperDescriptorType = ''
161+
# """
162+
# The type of methods of some built-in data types and base classes such as
163+
# :meth:`object.__init__` or :meth:`object.__lt__`.
164+
# """
165+
#
166+
# MethodWrapperType = ''
167+
# MethodDescriptorType = ''
168+
# ClassMethodDescriptorType = ''
169+
170+
# else:
171+
WrapperDescriptorType = type(object.__init__)
172+
MethodWrapperType = type(object().__str__)
173+
MethodDescriptorType = type(str.join)
174+
ClassMethodDescriptorType = type(dict.__dict__['fromkeys'])

0 commit comments

Comments
 (0)