typing-utilities 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- typing_utilities-0.0.0/LICENSE +21 -0
- typing_utilities-0.0.0/PKG-INFO +117 -0
- typing_utilities-0.0.0/README.md +85 -0
- typing_utilities-0.0.0/pyproject.toml +48 -0
- typing_utilities-0.0.0/setup.cfg +4 -0
- typing_utilities-0.0.0/src/typing_utilities.egg-info/PKG-INFO +117 -0
- typing_utilities-0.0.0/src/typing_utilities.egg-info/SOURCES.txt +18 -0
- typing_utilities-0.0.0/src/typing_utilities.egg-info/dependency_links.txt +1 -0
- typing_utilities-0.0.0/src/typing_utilities.egg-info/requires.txt +4 -0
- typing_utilities-0.0.0/src/typing_utilities.egg-info/top_level.txt +1 -0
- typing_utilities-0.0.0/src/typingutils/__init__.py +28 -0
- typing_utilities-0.0.0/src/typingutils/core/attributes.py +21 -0
- typing_utilities-0.0.0/src/typingutils/core/compatability.py +14 -0
- typing_utilities-0.0.0/src/typingutils/core/instances.py +241 -0
- typing_utilities-0.0.0/src/typingutils/core/types.py +365 -0
- typing_utilities-0.0.0/src/typingutils/internal.py +13 -0
- typing_utilities-0.0.0/tests/test_instances.py +110 -0
- typing_utilities-0.0.0/tests/test_isinstance.py +320 -0
- typing_utilities-0.0.0/tests/test_issubclass.py +233 -0
- typing_utilities-0.0.0/tests/test_types.py +327 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Dagrofa BI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: typing-utilities
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Runtime reflection and validation of types and generics.
|
|
5
|
+
Author-email: Anders Madsen <anders.madsen@alphavue.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: repository, https://github.com/apmadsen/typing-utilities
|
|
8
|
+
Keywords: windows,linux,generics,typing
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Development Status :: 6 - Mature
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Provides-Extra: test
|
|
29
|
+
Requires-Dist: pytest>=8.3; extra == "test"
|
|
30
|
+
Requires-Dist: pytest-cov>=6.1; extra == "test"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
[](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test.yml)
|
|
34
|
+
[](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test-coverage.yml)
|
|
35
|
+
[](https://github.com/apmadsen/typing-utilities/releases)
|
|
36
|
+

|
|
37
|
+

|
|
38
|
+
[](https://pepy.tech/projects/typing-utilities)
|
|
39
|
+
|
|
40
|
+
# typing-utilities: Runtime reflection and validation of types and generics.
|
|
41
|
+
|
|
42
|
+
`typing-utilities` extends Python with the ability to check instances and types of generic types and unions introduced in the `typing` module.
|
|
43
|
+
|
|
44
|
+
## Conventions
|
|
45
|
+
|
|
46
|
+
This project differs from Python and other projects in some aspects:
|
|
47
|
+
|
|
48
|
+
- Generic subscripted types like `list[str]` are always a subclass of its base type `list` whereas the opposite is not true.
|
|
49
|
+
- Any type is a subclass of `type[Any]`.
|
|
50
|
+
- `type[Any]` is not an instance of `type[Any]`.
|
|
51
|
+
- Builtin types and `typing` types are interchangeable, i.e. `list[T]` is interchangeable with `typing.List[T]` etc.
|
|
52
|
+
|
|
53
|
+
## What's not included
|
|
54
|
+
|
|
55
|
+
### Deep validation checks
|
|
56
|
+
|
|
57
|
+
This project does not check the contents of objects like lists and dicts, which is why `isinstance_typing([1, 2, 3], list[int])` returns false. The reason is, that while it's relatively easy to compare every item in a list to the type argument of `list[str]`, other generic types are not as straight forward, thus it's better left to the programmer.
|
|
58
|
+
|
|
59
|
+
### Generic types
|
|
60
|
+
|
|
61
|
+
It's not the goal of this project to deliver generic types such as generically enforced lists and dicts.
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
### Types
|
|
66
|
+
|
|
67
|
+
#### issubclass_typing
|
|
68
|
+
|
|
69
|
+
The `issubclass_typing(cls, base) -> bool` function extends the builtin `issubclass(cls, base)` function allowing both `cls` and `base` to be either a type, typevar or union object.
|
|
70
|
+
|
|
71
|
+
#### is_optional
|
|
72
|
+
|
|
73
|
+
The `is_optional(cls) -> bool` function checks whenter or not type is optional, i.e. a union containing `None` a `typing.Optional[T]` or `typing.Union[T, None]`
|
|
74
|
+
|
|
75
|
+
#### is_union
|
|
76
|
+
|
|
77
|
+
The `is_union(cls) -> bool` function checks whenter or not type is a union. This includes both `x|y` and `typing.Union` unions.
|
|
78
|
+
|
|
79
|
+
#### is_subscripted_generic_type
|
|
80
|
+
|
|
81
|
+
The `is_subscripted_generic_type(cls) -> bool` function indicates whether or not `cls` is a subscripted generic type as `list[str]` is a subscripted generic type of `list[T]` etc.
|
|
82
|
+
|
|
83
|
+
#### is_generic_type
|
|
84
|
+
|
|
85
|
+
The `is_generic_type(cls) -> bool` function indicates whether or not `cls` is a generic type like `list[T]`.
|
|
86
|
+
|
|
87
|
+
#### get_type_name
|
|
88
|
+
|
|
89
|
+
The `get_type_name(cls) -> str` function returns the name of type `cls`. It's used throughout the tests of this package and for documentational purposes.
|
|
90
|
+
|
|
91
|
+
#### get_optional_type
|
|
92
|
+
|
|
93
|
+
The `get_optional_type(cls) -> tuple[type|union, bool]` function extracts any types from `cls` regardless if it's an ordinary type, a union or a `typing.Optional[T]` object, and returns it along with a bool indicatig if optional or not.
|
|
94
|
+
|
|
95
|
+
### Objects
|
|
96
|
+
|
|
97
|
+
#### isinstance_typing
|
|
98
|
+
|
|
99
|
+
The `isinstance_typing(obj, cls) -> bool` function extends the builtin `isinstance(obj, cls)` function allowing `cls` to be either a type, typevar or union object.
|
|
100
|
+
|
|
101
|
+
#### is_type
|
|
102
|
+
|
|
103
|
+
The `is_type(obj) -> bool` function checks whenter or not `obj` is recognized as a type. This includes unions and `type[Any]`.
|
|
104
|
+
|
|
105
|
+
### Internal
|
|
106
|
+
|
|
107
|
+
#### get_generic_arguments
|
|
108
|
+
|
|
109
|
+
The `internal.get_generic_arguments(obj) -> tuple[type|union, ...]` function returns the types used to create the subscripted generic type or instance `obj`.
|
|
110
|
+
|
|
111
|
+
#### get_generic_parameters
|
|
112
|
+
|
|
113
|
+
The `internal.get_generic_parameters(cls) -> tuple[type|union|TypeVar, ...]` function returns the typevars needed to create a subscripted generic type derived frol `cls`.
|
|
114
|
+
|
|
115
|
+
## Other similar projects
|
|
116
|
+
|
|
117
|
+
There are other similar projects out there like [typing-utils](https://pypi.org/project/typing-utils/) and [runtype](https://pypi.org/project/runtype/), and while typing-utils is outdated and pretty basic, runtype is very similar to `typing-utilities` when it comes to validation.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
[](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test.yml)
|
|
2
|
+
[](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test-coverage.yml)
|
|
3
|
+
[](https://github.com/apmadsen/typing-utilities/releases)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
[](https://pepy.tech/projects/typing-utilities)
|
|
7
|
+
|
|
8
|
+
# typing-utilities: Runtime reflection and validation of types and generics.
|
|
9
|
+
|
|
10
|
+
`typing-utilities` extends Python with the ability to check instances and types of generic types and unions introduced in the `typing` module.
|
|
11
|
+
|
|
12
|
+
## Conventions
|
|
13
|
+
|
|
14
|
+
This project differs from Python and other projects in some aspects:
|
|
15
|
+
|
|
16
|
+
- Generic subscripted types like `list[str]` are always a subclass of its base type `list` whereas the opposite is not true.
|
|
17
|
+
- Any type is a subclass of `type[Any]`.
|
|
18
|
+
- `type[Any]` is not an instance of `type[Any]`.
|
|
19
|
+
- Builtin types and `typing` types are interchangeable, i.e. `list[T]` is interchangeable with `typing.List[T]` etc.
|
|
20
|
+
|
|
21
|
+
## What's not included
|
|
22
|
+
|
|
23
|
+
### Deep validation checks
|
|
24
|
+
|
|
25
|
+
This project does not check the contents of objects like lists and dicts, which is why `isinstance_typing([1, 2, 3], list[int])` returns false. The reason is, that while it's relatively easy to compare every item in a list to the type argument of `list[str]`, other generic types are not as straight forward, thus it's better left to the programmer.
|
|
26
|
+
|
|
27
|
+
### Generic types
|
|
28
|
+
|
|
29
|
+
It's not the goal of this project to deliver generic types such as generically enforced lists and dicts.
|
|
30
|
+
|
|
31
|
+
## API
|
|
32
|
+
|
|
33
|
+
### Types
|
|
34
|
+
|
|
35
|
+
#### issubclass_typing
|
|
36
|
+
|
|
37
|
+
The `issubclass_typing(cls, base) -> bool` function extends the builtin `issubclass(cls, base)` function allowing both `cls` and `base` to be either a type, typevar or union object.
|
|
38
|
+
|
|
39
|
+
#### is_optional
|
|
40
|
+
|
|
41
|
+
The `is_optional(cls) -> bool` function checks whenter or not type is optional, i.e. a union containing `None` a `typing.Optional[T]` or `typing.Union[T, None]`
|
|
42
|
+
|
|
43
|
+
#### is_union
|
|
44
|
+
|
|
45
|
+
The `is_union(cls) -> bool` function checks whenter or not type is a union. This includes both `x|y` and `typing.Union` unions.
|
|
46
|
+
|
|
47
|
+
#### is_subscripted_generic_type
|
|
48
|
+
|
|
49
|
+
The `is_subscripted_generic_type(cls) -> bool` function indicates whether or not `cls` is a subscripted generic type as `list[str]` is a subscripted generic type of `list[T]` etc.
|
|
50
|
+
|
|
51
|
+
#### is_generic_type
|
|
52
|
+
|
|
53
|
+
The `is_generic_type(cls) -> bool` function indicates whether or not `cls` is a generic type like `list[T]`.
|
|
54
|
+
|
|
55
|
+
#### get_type_name
|
|
56
|
+
|
|
57
|
+
The `get_type_name(cls) -> str` function returns the name of type `cls`. It's used throughout the tests of this package and for documentational purposes.
|
|
58
|
+
|
|
59
|
+
#### get_optional_type
|
|
60
|
+
|
|
61
|
+
The `get_optional_type(cls) -> tuple[type|union, bool]` function extracts any types from `cls` regardless if it's an ordinary type, a union or a `typing.Optional[T]` object, and returns it along with a bool indicatig if optional or not.
|
|
62
|
+
|
|
63
|
+
### Objects
|
|
64
|
+
|
|
65
|
+
#### isinstance_typing
|
|
66
|
+
|
|
67
|
+
The `isinstance_typing(obj, cls) -> bool` function extends the builtin `isinstance(obj, cls)` function allowing `cls` to be either a type, typevar or union object.
|
|
68
|
+
|
|
69
|
+
#### is_type
|
|
70
|
+
|
|
71
|
+
The `is_type(obj) -> bool` function checks whenter or not `obj` is recognized as a type. This includes unions and `type[Any]`.
|
|
72
|
+
|
|
73
|
+
### Internal
|
|
74
|
+
|
|
75
|
+
#### get_generic_arguments
|
|
76
|
+
|
|
77
|
+
The `internal.get_generic_arguments(obj) -> tuple[type|union, ...]` function returns the types used to create the subscripted generic type or instance `obj`.
|
|
78
|
+
|
|
79
|
+
#### get_generic_parameters
|
|
80
|
+
|
|
81
|
+
The `internal.get_generic_parameters(cls) -> tuple[type|union|TypeVar, ...]` function returns the typevars needed to create a subscripted generic type derived frol `cls`.
|
|
82
|
+
|
|
83
|
+
## Other similar projects
|
|
84
|
+
|
|
85
|
+
There are other similar projects out there like [typing-utils](https://pypi.org/project/typing-utils/) and [runtype](https://pypi.org/project/runtype/), and while typing-utils is outdated and pretty basic, runtype is very similar to `typing-utilities` when it comes to validation.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "typing-utilities"
|
|
3
|
+
version = "0.0.0"
|
|
4
|
+
description = "Runtime reflection and validation of types and generics."
|
|
5
|
+
keywords = ["windows", "linux", "generics", "typing"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "Anders Madsen", email = "anders.madsen@alphavue.com" }
|
|
9
|
+
]
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 5 - Production/Stable",
|
|
13
|
+
"Development Status :: 6 - Mature",
|
|
14
|
+
"Operating System :: Microsoft :: Windows",
|
|
15
|
+
"Operating System :: POSIX :: Linux",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Natural Language :: English",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Topic :: Software Development :: Libraries",
|
|
27
|
+
"Typing :: Typed"
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
|
|
31
|
+
]
|
|
32
|
+
requires-python = ">=3.10"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
repository = "https://github.com/apmadsen/typing-utilities"
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
test = [
|
|
39
|
+
"pytest>=8.3",
|
|
40
|
+
"pytest-cov>=6.1",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools-git-versioning]
|
|
44
|
+
enabled = true
|
|
45
|
+
|
|
46
|
+
[build-system]
|
|
47
|
+
requires = ["setuptools >= 77.0.3", "setuptools-git-versioning >= 2.1.0"]
|
|
48
|
+
build-backend = "setuptools.build_meta"
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: typing-utilities
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Runtime reflection and validation of types and generics.
|
|
5
|
+
Author-email: Anders Madsen <anders.madsen@alphavue.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: repository, https://github.com/apmadsen/typing-utilities
|
|
8
|
+
Keywords: windows,linux,generics,typing
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Development Status :: 6 - Mature
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Provides-Extra: test
|
|
29
|
+
Requires-Dist: pytest>=8.3; extra == "test"
|
|
30
|
+
Requires-Dist: pytest-cov>=6.1; extra == "test"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
[](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test.yml)
|
|
34
|
+
[](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test-coverage.yml)
|
|
35
|
+
[](https://github.com/apmadsen/typing-utilities/releases)
|
|
36
|
+

|
|
37
|
+

|
|
38
|
+
[](https://pepy.tech/projects/typing-utilities)
|
|
39
|
+
|
|
40
|
+
# typing-utilities: Runtime reflection and validation of types and generics.
|
|
41
|
+
|
|
42
|
+
`typing-utilities` extends Python with the ability to check instances and types of generic types and unions introduced in the `typing` module.
|
|
43
|
+
|
|
44
|
+
## Conventions
|
|
45
|
+
|
|
46
|
+
This project differs from Python and other projects in some aspects:
|
|
47
|
+
|
|
48
|
+
- Generic subscripted types like `list[str]` are always a subclass of its base type `list` whereas the opposite is not true.
|
|
49
|
+
- Any type is a subclass of `type[Any]`.
|
|
50
|
+
- `type[Any]` is not an instance of `type[Any]`.
|
|
51
|
+
- Builtin types and `typing` types are interchangeable, i.e. `list[T]` is interchangeable with `typing.List[T]` etc.
|
|
52
|
+
|
|
53
|
+
## What's not included
|
|
54
|
+
|
|
55
|
+
### Deep validation checks
|
|
56
|
+
|
|
57
|
+
This project does not check the contents of objects like lists and dicts, which is why `isinstance_typing([1, 2, 3], list[int])` returns false. The reason is, that while it's relatively easy to compare every item in a list to the type argument of `list[str]`, other generic types are not as straight forward, thus it's better left to the programmer.
|
|
58
|
+
|
|
59
|
+
### Generic types
|
|
60
|
+
|
|
61
|
+
It's not the goal of this project to deliver generic types such as generically enforced lists and dicts.
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
### Types
|
|
66
|
+
|
|
67
|
+
#### issubclass_typing
|
|
68
|
+
|
|
69
|
+
The `issubclass_typing(cls, base) -> bool` function extends the builtin `issubclass(cls, base)` function allowing both `cls` and `base` to be either a type, typevar or union object.
|
|
70
|
+
|
|
71
|
+
#### is_optional
|
|
72
|
+
|
|
73
|
+
The `is_optional(cls) -> bool` function checks whenter or not type is optional, i.e. a union containing `None` a `typing.Optional[T]` or `typing.Union[T, None]`
|
|
74
|
+
|
|
75
|
+
#### is_union
|
|
76
|
+
|
|
77
|
+
The `is_union(cls) -> bool` function checks whenter or not type is a union. This includes both `x|y` and `typing.Union` unions.
|
|
78
|
+
|
|
79
|
+
#### is_subscripted_generic_type
|
|
80
|
+
|
|
81
|
+
The `is_subscripted_generic_type(cls) -> bool` function indicates whether or not `cls` is a subscripted generic type as `list[str]` is a subscripted generic type of `list[T]` etc.
|
|
82
|
+
|
|
83
|
+
#### is_generic_type
|
|
84
|
+
|
|
85
|
+
The `is_generic_type(cls) -> bool` function indicates whether or not `cls` is a generic type like `list[T]`.
|
|
86
|
+
|
|
87
|
+
#### get_type_name
|
|
88
|
+
|
|
89
|
+
The `get_type_name(cls) -> str` function returns the name of type `cls`. It's used throughout the tests of this package and for documentational purposes.
|
|
90
|
+
|
|
91
|
+
#### get_optional_type
|
|
92
|
+
|
|
93
|
+
The `get_optional_type(cls) -> tuple[type|union, bool]` function extracts any types from `cls` regardless if it's an ordinary type, a union or a `typing.Optional[T]` object, and returns it along with a bool indicatig if optional or not.
|
|
94
|
+
|
|
95
|
+
### Objects
|
|
96
|
+
|
|
97
|
+
#### isinstance_typing
|
|
98
|
+
|
|
99
|
+
The `isinstance_typing(obj, cls) -> bool` function extends the builtin `isinstance(obj, cls)` function allowing `cls` to be either a type, typevar or union object.
|
|
100
|
+
|
|
101
|
+
#### is_type
|
|
102
|
+
|
|
103
|
+
The `is_type(obj) -> bool` function checks whenter or not `obj` is recognized as a type. This includes unions and `type[Any]`.
|
|
104
|
+
|
|
105
|
+
### Internal
|
|
106
|
+
|
|
107
|
+
#### get_generic_arguments
|
|
108
|
+
|
|
109
|
+
The `internal.get_generic_arguments(obj) -> tuple[type|union, ...]` function returns the types used to create the subscripted generic type or instance `obj`.
|
|
110
|
+
|
|
111
|
+
#### get_generic_parameters
|
|
112
|
+
|
|
113
|
+
The `internal.get_generic_parameters(cls) -> tuple[type|union|TypeVar, ...]` function returns the typevars needed to create a subscripted generic type derived frol `cls`.
|
|
114
|
+
|
|
115
|
+
## Other similar projects
|
|
116
|
+
|
|
117
|
+
There are other similar projects out there like [typing-utils](https://pypi.org/project/typing-utils/) and [runtype](https://pypi.org/project/runtype/), and while typing-utils is outdated and pretty basic, runtype is very similar to `typing-utilities` when it comes to validation.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/typing_utilities.egg-info/PKG-INFO
|
|
5
|
+
src/typing_utilities.egg-info/SOURCES.txt
|
|
6
|
+
src/typing_utilities.egg-info/dependency_links.txt
|
|
7
|
+
src/typing_utilities.egg-info/requires.txt
|
|
8
|
+
src/typing_utilities.egg-info/top_level.txt
|
|
9
|
+
src/typingutils/__init__.py
|
|
10
|
+
src/typingutils/internal.py
|
|
11
|
+
src/typingutils/core/attributes.py
|
|
12
|
+
src/typingutils/core/compatability.py
|
|
13
|
+
src/typingutils/core/instances.py
|
|
14
|
+
src/typingutils/core/types.py
|
|
15
|
+
tests/test_instances.py
|
|
16
|
+
tests/test_isinstance.py
|
|
17
|
+
tests/test_issubclass.py
|
|
18
|
+
tests/test_types.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
typingutils
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from typingutils.core.instances import (
|
|
2
|
+
isinstance_typing, is_type, is_subscripted_generic_type,
|
|
3
|
+
get_generic_arguments
|
|
4
|
+
)
|
|
5
|
+
from typingutils.core.types import (
|
|
6
|
+
get_type_name, issubclass_typing, is_optional, get_optional_type,
|
|
7
|
+
is_generic_type, is_union, get_generic_parameters,
|
|
8
|
+
TypeParameter, UnionParameter, AnyType,
|
|
9
|
+
TypeArgs
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
'TypeParameter',
|
|
14
|
+
'UnionParameter',
|
|
15
|
+
'AnyType',
|
|
16
|
+
'TypeArgs',
|
|
17
|
+
'isinstance_typing',
|
|
18
|
+
'issubclass_typing',
|
|
19
|
+
'is_type',
|
|
20
|
+
'is_subscripted_generic_type',
|
|
21
|
+
'is_generic_type',
|
|
22
|
+
'is_optional',
|
|
23
|
+
'is_union',
|
|
24
|
+
'get_type_name',
|
|
25
|
+
'get_optional_type',
|
|
26
|
+
'get_generic_arguments',
|
|
27
|
+
'get_generic_parameters',
|
|
28
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
INIT = "__init__"
|
|
2
|
+
NEW = "__new__"
|
|
3
|
+
CLASS = "__class__"
|
|
4
|
+
GENERIC_CONSTRUCTOR = "__class_getitem__"
|
|
5
|
+
SPECIAL_CONSTRUCTOR = "__getitem__"
|
|
6
|
+
ORIGIN = "__origin__"
|
|
7
|
+
ORIGINAL_CLASS = "__orig_class__"
|
|
8
|
+
ARGS = "__args__"
|
|
9
|
+
PARAMETERS = "__parameters__"
|
|
10
|
+
BASES = "__bases__"
|
|
11
|
+
NAME = "__name__"
|
|
12
|
+
QUALIFIED_NAME = "__qualname__"
|
|
13
|
+
MODULE = "__module__"
|
|
14
|
+
ANNOTATIONS = "__annotations__"
|
|
15
|
+
DICT = "__dict__"
|
|
16
|
+
SELF = "__self__"
|
|
17
|
+
GLOBALS = "__globals__"
|
|
18
|
+
IM_CLASS = "im_class"
|
|
19
|
+
WRAPPED = "__wrapped__"
|
|
20
|
+
BOUND = "__bound__"
|
|
21
|
+
CONSTRAINTS = "__constraints__"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# pragma: no cover
|
|
2
|
+
from sys import version_info
|
|
3
|
+
|
|
4
|
+
PYTHON_310 = version_info.major == 3 and version_info.minor == 10
|
|
5
|
+
PYTHON_LT_310 = version_info.major == 3 and version_info.minor < 10
|
|
6
|
+
PYTHON_GTE_310 = version_info.major == 3 and version_info.minor >= 10
|
|
7
|
+
PYTHON_311 = version_info.major == 3 and version_info.minor == 11
|
|
8
|
+
PYTHON_GTE_311 = version_info.major == 3 and version_info.minor >= 11
|
|
9
|
+
PYTHON_312 = version_info.major == 3 and version_info.minor == 12
|
|
10
|
+
PYTHON_GTE_312 = version_info.major == 3 and version_info.minor >= 12
|
|
11
|
+
PYTHON_313 = version_info.major == 3 and version_info.minor == 13
|
|
12
|
+
PYTHON_GTE_313 = version_info.major == 3 and version_info.minor >= 13
|
|
13
|
+
PYTHON_GTE_314 = version_info.major == 3 and version_info.minor >= 14
|
|
14
|
+
PYTHON_SUPPORTED = PYTHON_GTE_310
|