Skip to content

Commit 002bfc9

Browse files
committed
Add PathType TypeVar to typing
1 parent de815f5 commit 002bfc9

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

doc-source/api/typing.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@
77

88
.. data:: WrapperDescriptorType
99

10-
The type of methods of some built-in data types and base classes such as
10+
The type of methods of some built-in data types and base classes, such as
1111
:meth:`object.__init__` or :meth:`object.__lt__`.
1212

1313
.. versionadded:: 0.8.0
1414

1515
.. data:: MethodWrapperType
1616

1717
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__`.
18+
For example, it is the type of :code:`object().__str__`.
1919

2020
.. versionadded:: 0.8.0
2121

2222

2323
.. data:: MethodDescriptorType
2424

25-
The type of methods of some built-in data types such as :meth:`str.join`.
25+
The type of methods of some built-in data types, such as :meth:`str.join`.
2626

2727
.. versionadded:: 0.8.0
2828

2929

3030
.. data:: ClassMethodDescriptorType
3131

32-
The type of *unbound* class methods of some built-in data types such as
32+
The type of *unbound* class methods of some built-in data types, such as
3333
``dict.__dict__['fromkeys']``.
3434

3535
.. versionadded:: 0.8.0

domdf_python_tools/typing.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
__all__ = [
6464
"PathLike",
65+
"PathType",
6566
"AnyNumber",
6667
"check_membership",
6768
"JsonLibrary",
@@ -75,8 +76,21 @@
7576
"SupportsIndex",
7677
]
7778

78-
#: Type hint for objects that represent filesystem paths.
7979
PathLike = Union[str, pathlib.Path, os.PathLike]
80+
"""
81+
Type hint for objects that represent filesystem paths.
82+
83+
.. seealso:: :py:obj:`domdf_python_tools.typing.PathType`
84+
"""
85+
86+
PathType = typing.TypeVar("PathType", str, pathlib.Path, os.PathLike)
87+
"""
88+
Type variable for objects that represent filesystem paths.
89+
90+
.. versionadded:: 2.2.0
91+
92+
.. seealso:: :py:obj:`domdf_python_tools.typing.PathLike`
93+
"""
8094

8195
AnyNumber = Union[float, int, Decimal]
8296
"""
@@ -93,7 +107,8 @@ def check_membership(obj: Any, type_: Union[Type, object]) -> bool:
93107
Check if the type of ``obj`` is one of the types in a :py:data:`typing.Union`, :class:`typing.Sequence` etc.
94108
95109
:param obj: The object to check the type of
96-
:param type\_: A :class:`~typing.Type` that has members, such as a List, Union or Sequence.
110+
:param type\_: A :class:`~typing.Type` that has members,
111+
such as a :class:`typing.List`, :py:data:`typing.Union` or :py:class:`typing.Sequence`.
97112
"""
98113

99114
return isinstance(obj, type_.__args__) # type: ignore

0 commit comments

Comments
 (0)