diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-04-10 17:25:07 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-04-10 17:25:07 +0000 |
| commit | 079ad7a0b3dd4c517a92d227fc5b96f38186c8f7 (patch) | |
| tree | d4a28793df4b0ec14cd4f149da4951f52ac9ca54 | |
| parent | ddc05229c526deb4d791e73c40fbd5e757673ef5 (diff) | |
automatic import of python-typing-utils
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-typing-utils.spec | 481 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 483 insertions, 0 deletions
@@ -0,0 +1 @@ +/typing_utils-0.1.0.tar.gz diff --git a/python-typing-utils.spec b/python-typing-utils.spec new file mode 100644 index 0000000..8009fd1 --- /dev/null +++ b/python-typing-utils.spec @@ -0,0 +1,481 @@ +%global _empty_manifest_terminate_build 0 +Name: python-typing-utils +Version: 0.1.0 +Release: 1 +Summary: utils to inspect Python type annotations +License: Apache License 2.0 +URL: https://github.com/bojiang/typing_utils +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/c0/9f/ddc5ed9182f49d6ca5d87a7629dea81ca076db54f30f78d057a081f5ec50/typing_utils-0.1.0.tar.gz +BuildArch: noarch + +Requires: python3-pytest + +%description +# typing-utils + +Backport Python3.8+ typing utils & issubtype & more + +- [Install](#install) +- [API](#api) + - [issubtype](#issubtype) + - [get_origin](#get_origin) + - [get_args](#get_args) + - [get_type_hints](#get_type_hints) + +[](https://github.com/bojiang/typing_utils/actions/workflows/py36.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py37.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py38.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py39.yml) + +## Install + +``` bash + pip install typing_utils +``` + + +## API + +- [issubtype](#issubtype) +- [get_origin](#get_origin) +- [get_args](#get_args) +- [get_type_hints](#get_type_hints) + + +### issubtype + +Check that the left argument is a subtype of the right. + +For unions, check if the type arguments of the left is a subset of the right. +Also works for nested types including ForwardRefs. + +Examples: + +```python + from typing_utils import issubtype + + issubtype(typing.List, typing.Any) == True + issubtype(list, list) == True + issubtype(list, typing.List) == True + issubtype(list, typing.Sequence) == True + issubtype(typing.List[int], list) == True + issubtype(typing.List[typing.List], list) == True + issubtype(list, typing.List[int]) == False + issubtype(list, typing.Union[typing.Tuple, typing.Set]) == False + issubtype(typing.List[typing.List], typing.List[typing.Sequence]) == True + JSON = typing.Union[ + int, float, bool, str, None, typing.Sequence["JSON"], + typing.Mapping[str, "JSON"] + ] + issubtype(str, JSON, forward_refs={'JSON': JSON}) == True + issubtype(typing.Dict[str, str], JSON, forward_refs={'JSON': JSON}) == True + issubtype(typing.Dict[str, bytes], JSON, forward_refs={'JSON': JSON}) == False +``` + + +### get_origin + +Get the unsubscripted version of a type. + +This supports generic types, Callable, Tuple, Union, Literal, Final and ClassVar. +Return None for unsupported types. + +Examples: + +```python + from typing_utils import get_origin + + get_origin(Literal[42]) is Literal + get_origin(int) is None + get_origin(ClassVar[int]) is ClassVar + get_origin(Generic) is Generic + get_origin(Generic[T]) is Generic + get_origin(Union[T, int]) is Union + get_origin(List[Tuple[T, T]][int]) == list +``` + + +### get_args + +Get type arguments with all substitutions performed. + +For unions, basic simplifications used by Union constructor are performed. + +Examples: + +```python + from typing_utils import get_args + + get_args(Dict[str, int]) == (str, int) + get_args(int) == () + get_args(Union[int, Union[T, int], str][int]) == (int, str) + get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) + get_args(Callable[[], T][int]) == ([], int) +``` + + +### get_type_hints + +Return type hints for an object. + + +This is often the same as obj.__annotations__, but it handles +forward references encoded as string literals, and if necessary +adds Optional[t] if a default value equal to None is set. + +The argument may be a module, class, method, or function. The annotations +are returned as a dictionary. For classes, annotations include also +inherited members. + +TypeError is raised if the argument is not of a type that can contain +annotations, and an empty dictionary is returned if no annotations are +present. + +BEWARE -- the behavior of globalns and localns is counterintuitive +(unless you are familiar with how eval() and exec() work). The +search order is locals first, then globals. + +- If no dict arguments are passed, an attempt is made to use the + globals from obj (or the respective module's globals for classes), + and these are also used as the locals. If the object does not appear + to have globals, an empty dictionary is used. + +- If one dict argument is passed, it is used for both globals and + locals. + +- If two dict arguments are passed, they specify globals and + locals, respectively. + + + + +%package -n python3-typing-utils +Summary: utils to inspect Python type annotations +Provides: python-typing-utils +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-typing-utils +# typing-utils + +Backport Python3.8+ typing utils & issubtype & more + +- [Install](#install) +- [API](#api) + - [issubtype](#issubtype) + - [get_origin](#get_origin) + - [get_args](#get_args) + - [get_type_hints](#get_type_hints) + +[](https://github.com/bojiang/typing_utils/actions/workflows/py36.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py37.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py38.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py39.yml) + +## Install + +``` bash + pip install typing_utils +``` + + +## API + +- [issubtype](#issubtype) +- [get_origin](#get_origin) +- [get_args](#get_args) +- [get_type_hints](#get_type_hints) + + +### issubtype + +Check that the left argument is a subtype of the right. + +For unions, check if the type arguments of the left is a subset of the right. +Also works for nested types including ForwardRefs. + +Examples: + +```python + from typing_utils import issubtype + + issubtype(typing.List, typing.Any) == True + issubtype(list, list) == True + issubtype(list, typing.List) == True + issubtype(list, typing.Sequence) == True + issubtype(typing.List[int], list) == True + issubtype(typing.List[typing.List], list) == True + issubtype(list, typing.List[int]) == False + issubtype(list, typing.Union[typing.Tuple, typing.Set]) == False + issubtype(typing.List[typing.List], typing.List[typing.Sequence]) == True + JSON = typing.Union[ + int, float, bool, str, None, typing.Sequence["JSON"], + typing.Mapping[str, "JSON"] + ] + issubtype(str, JSON, forward_refs={'JSON': JSON}) == True + issubtype(typing.Dict[str, str], JSON, forward_refs={'JSON': JSON}) == True + issubtype(typing.Dict[str, bytes], JSON, forward_refs={'JSON': JSON}) == False +``` + + +### get_origin + +Get the unsubscripted version of a type. + +This supports generic types, Callable, Tuple, Union, Literal, Final and ClassVar. +Return None for unsupported types. + +Examples: + +```python + from typing_utils import get_origin + + get_origin(Literal[42]) is Literal + get_origin(int) is None + get_origin(ClassVar[int]) is ClassVar + get_origin(Generic) is Generic + get_origin(Generic[T]) is Generic + get_origin(Union[T, int]) is Union + get_origin(List[Tuple[T, T]][int]) == list +``` + + +### get_args + +Get type arguments with all substitutions performed. + +For unions, basic simplifications used by Union constructor are performed. + +Examples: + +```python + from typing_utils import get_args + + get_args(Dict[str, int]) == (str, int) + get_args(int) == () + get_args(Union[int, Union[T, int], str][int]) == (int, str) + get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) + get_args(Callable[[], T][int]) == ([], int) +``` + + +### get_type_hints + +Return type hints for an object. + + +This is often the same as obj.__annotations__, but it handles +forward references encoded as string literals, and if necessary +adds Optional[t] if a default value equal to None is set. + +The argument may be a module, class, method, or function. The annotations +are returned as a dictionary. For classes, annotations include also +inherited members. + +TypeError is raised if the argument is not of a type that can contain +annotations, and an empty dictionary is returned if no annotations are +present. + +BEWARE -- the behavior of globalns and localns is counterintuitive +(unless you are familiar with how eval() and exec() work). The +search order is locals first, then globals. + +- If no dict arguments are passed, an attempt is made to use the + globals from obj (or the respective module's globals for classes), + and these are also used as the locals. If the object does not appear + to have globals, an empty dictionary is used. + +- If one dict argument is passed, it is used for both globals and + locals. + +- If two dict arguments are passed, they specify globals and + locals, respectively. + + + + +%package help +Summary: Development documents and examples for typing-utils +Provides: python3-typing-utils-doc +%description help +# typing-utils + +Backport Python3.8+ typing utils & issubtype & more + +- [Install](#install) +- [API](#api) + - [issubtype](#issubtype) + - [get_origin](#get_origin) + - [get_args](#get_args) + - [get_type_hints](#get_type_hints) + +[](https://github.com/bojiang/typing_utils/actions/workflows/py36.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py37.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py38.yml) +[](https://github.com/bojiang/typing_utils/actions/workflows/py39.yml) + +## Install + +``` bash + pip install typing_utils +``` + + +## API + +- [issubtype](#issubtype) +- [get_origin](#get_origin) +- [get_args](#get_args) +- [get_type_hints](#get_type_hints) + + +### issubtype + +Check that the left argument is a subtype of the right. + +For unions, check if the type arguments of the left is a subset of the right. +Also works for nested types including ForwardRefs. + +Examples: + +```python + from typing_utils import issubtype + + issubtype(typing.List, typing.Any) == True + issubtype(list, list) == True + issubtype(list, typing.List) == True + issubtype(list, typing.Sequence) == True + issubtype(typing.List[int], list) == True + issubtype(typing.List[typing.List], list) == True + issubtype(list, typing.List[int]) == False + issubtype(list, typing.Union[typing.Tuple, typing.Set]) == False + issubtype(typing.List[typing.List], typing.List[typing.Sequence]) == True + JSON = typing.Union[ + int, float, bool, str, None, typing.Sequence["JSON"], + typing.Mapping[str, "JSON"] + ] + issubtype(str, JSON, forward_refs={'JSON': JSON}) == True + issubtype(typing.Dict[str, str], JSON, forward_refs={'JSON': JSON}) == True + issubtype(typing.Dict[str, bytes], JSON, forward_refs={'JSON': JSON}) == False +``` + + +### get_origin + +Get the unsubscripted version of a type. + +This supports generic types, Callable, Tuple, Union, Literal, Final and ClassVar. +Return None for unsupported types. + +Examples: + +```python + from typing_utils import get_origin + + get_origin(Literal[42]) is Literal + get_origin(int) is None + get_origin(ClassVar[int]) is ClassVar + get_origin(Generic) is Generic + get_origin(Generic[T]) is Generic + get_origin(Union[T, int]) is Union + get_origin(List[Tuple[T, T]][int]) == list +``` + + +### get_args + +Get type arguments with all substitutions performed. + +For unions, basic simplifications used by Union constructor are performed. + +Examples: + +```python + from typing_utils import get_args + + get_args(Dict[str, int]) == (str, int) + get_args(int) == () + get_args(Union[int, Union[T, int], str][int]) == (int, str) + get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) + get_args(Callable[[], T][int]) == ([], int) +``` + + +### get_type_hints + +Return type hints for an object. + + +This is often the same as obj.__annotations__, but it handles +forward references encoded as string literals, and if necessary +adds Optional[t] if a default value equal to None is set. + +The argument may be a module, class, method, or function. The annotations +are returned as a dictionary. For classes, annotations include also +inherited members. + +TypeError is raised if the argument is not of a type that can contain +annotations, and an empty dictionary is returned if no annotations are +present. + +BEWARE -- the behavior of globalns and localns is counterintuitive +(unless you are familiar with how eval() and exec() work). The +search order is locals first, then globals. + +- If no dict arguments are passed, an attempt is made to use the + globals from obj (or the respective module's globals for classes), + and these are also used as the locals. If the object does not appear + to have globals, an empty dictionary is used. + +- If one dict argument is passed, it is used for both globals and + locals. + +- If two dict arguments are passed, they specify globals and + locals, respectively. + + + + +%prep +%autosetup -n typing-utils-0.1.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-typing-utils -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon Apr 10 2023 Python_Bot <Python_Bot@openeuler.org> - 0.1.0-1 +- Package Spec generated @@ -0,0 +1 @@ +5b7090f717563d437502b598105c6b4b typing_utils-0.1.0.tar.gz |
