comment here

This commit is contained in:
ton
2023-03-18 20:03:34 +07:00
commit 4553a0a589
14513 changed files with 2685043 additions and 0 deletions

View File

@@ -0,0 +1 @@
conda

View File

@@ -0,0 +1,7 @@
Copyright 2020, Ramon Hagenaars
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,216 @@
Metadata-Version: 2.1
Name: typish
Version: 1.9.3
Summary: Functionality for types
Home-page: https://github.com/ramonhagenaars/typish
Author: Ramon Hagenaars
Author-email: ramon.hagenaars@gmail.com
License: MIT
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Description-Content-Type: text/markdown
Provides-Extra: test
Requires-Dist: numpy ; extra == 'test'
Requires-Dist: nptyping (>=1.3.0) ; extra == 'test'
Requires-Dist: pycodestyle ; extra == 'test'
Requires-Dist: pylint ; extra == 'test'
Requires-Dist: mypy ; extra == 'test'
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: coverage ; extra == 'test'
Requires-Dist: codecov ; extra == 'test'
[![image](https://img.shields.io/pypi/pyversions/typish.svg)](https://pypi.org/project/typish/)
[![Downloads](https://pepy.tech/badge/typish)](https://pepy.tech/project/typish)
[![Pypi version](https://badge.fury.io/py/typish.svg)](https://badge.fury.io/py/typish)
[![codecov](https://codecov.io/gh/ramonhagenaars/typish/branch/master/graph/badge.svg)](https://codecov.io/gh/ramonhagenaars/typish)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ramonhagenaars/typish/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ramonhagenaars/typish/?branch=master)
# Typish
* Functions for thorough checks on types
* Instance checks considering generics
* Typesafe Duck-typing
## Example
```python
>>> from typing import Iterable
>>> from typish import instance_of
>>> instance_of([1, 2, 3], Iterable[int])
True
```
## Installation
```
pip install typish
```
## Content
### Functions
| Function | Description
|---|---
| ``subclass_of(cls: type, *args: type) -> bool`` | Returns whether ``cls`` is a sub type of *all* types in ``args``
| ``instance_of(obj: object, *args: type) -> bool`` | Returns whether ``cls`` is an instance of *all* types in ``args``
| ``get_origin(t: type) -> type`` | Return the "origin" of a generic type. E.g. ``get_origin(List[str])`` gives ``list``.
| ``get_args(t: type) -> typing.Tuple[type, ...]`` | Return the arguments of a generic type. E.g. ``get_args(List[str])`` gives ``(str, )``.
| ``get_alias(cls: T) -> typing.Optional[T]`` | Return the ``typing`` alias for a type. E.g ``get_alias(list)`` gives ``List``.
| ``get_type(inst: T, use_union: bool = False) -> typing.Type[T]`` | Return the (generic) type of an instance. E.g. a list of ints will give ``List[int]``.
| ``common_ancestor(*args: object) -> type`` | Return the closest common ancestor of the given instances.
| ``common_ancestor_of_types(*args: type) -> type`` | Return the closest common ancestor of the given classes.
| ``get_args_and_return_type(hint: typing.Type[typing.Callable]) -> typing.Tuple[typing.Optional[typing.Tuple[type]], typing.Optional[type]]`` | Get the argument types and the return type of a callable type hint (e.g. ``Callable[[int], str]``).
| ``get_type_hints_of_callable(func: typing.Callable) -> typing.Dict[str, type]`` | Return the type hints of the parameters of the given callable.
| ``is_type_annotation(item: typing.Any) -> bool`` | Returns whether ``item`` is a ``type`` or a ``typing`` type.
| ``is_from_typing(cls: type) -> bool`` | Returns whether ``cls`` is from the ``typing`` module.
| ``is_optional_type(cls: type) -> bool`` | Returns whether ``cls`` is considered to be an optional type.
| ``get_mro(obj: typing.Any) -> typing.Tuple[type, ...]`` | Wrapper around ``getmro`` from ``inspect`` to also support ``typing`` types.
### Types
| Type | Description
|---|---|
| ``T`` | A generic Type var.
| ``KT`` | A Type var for keys in a dict.
| ``VT`` | A type var for values in a dict.
| ``Empty`` | The type of emptiness (= ``Parameter.empty``).
| ``Unknown`` | The type of something unknown.
| ``Module`` | The type of a module.
| ``NoneType`` | The type of ``None``.
| ``EllipsisType`` | The type of ``...``.
### Decorators
#### hintable
This decorator allows one to capture the type hint of a variable that calls a function. If no hint is provided, `None`
is passed as a value for `hint`.
Just remember: with great power comes great responsibility. Use this functionality wisely. You may want to make sure
that if you hinted a variable with a certain type, your `hintable` function does indeed return a value of that type.
```python
@hintable
def cast(arg: Any, hint: Type[T]) -> T:
return hint(arg)
# The type hint on x is passed to cast:
x: int = cast('42')
# It works with MyPy hints as well:
y = cast('42') # type: int
# Not something you would normally do, but the type hint takes precedence:
z: int = cast('42') # type: str
```
### Classes
#### SubscriptableType
This metaclass allows a type to become subscriptable.
*Example:*
```python
class MyClass(metaclass=SubscriptableType):
...
```
Now you can do:
```python
MyClass2 = MyClass['some args']
print(MyClass2.__args__)
print(MyClass2.__origin__)
```
Output:
```
some args
<class '__main__.MyClass'>
```
#### Something
Define an interface with ``typish.Something``.
*Example:*
```python
Duck = Something['walk': Callable[[], None],
'quack': Callable[[], None]]
```
Anything that has the attributes defined in ``Something`` with the right type is
considered an instance of that ``Something`` (classes, objects, even modules...).
The builtin ``isinstance`` is supported as well as ``typish.instance_of``.
#### ClsDict
A dictionary that uses instance checking to determine which value to return.
It only accepts types as keys.
This is particularly useful when a function accepts multiple types for an
argument and you want to split the implementation into separate functions.
*Example:*
```python
def _handle_str(item):
...
def _handle_int(item):
...
def func(item):
# Suppose item can be a string or an int, you can use ClsDict to
# pick a handler function.
cd = ClsDict({
str: _handle_str,
int: _handle_int,
})
handler = cd[item] # Pick the right handler.
handler(item) # Call that handler.
```
#### ClsFunction
A callable that uses `ClsDict` to call the right function.
Below is the same example as above, but slightly modified in
that it uses `ClsFunction`.
*Example:*
```python
def _handle_str(item):
...
def _handle_int(item):
...
def func(item):
# Suppose item can be a string or an int, you can use ClsFunction to
# delegate to the right handler function.
function = ClsFunction({
str: _handle_str,
int: _handle_int,
})
function(item)
```
#### Literal
A backwards compatible variant of typing.Literal (Python3.8). When importing
`Literal` from `typish`, you will get the `typing.Literal` if it is available.

View File

@@ -0,0 +1,62 @@
typish-1.9.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
typish-1.9.3.dist-info/LICENSE,sha256=U5aESM-JrgQzUE4dkZ7D88AYu3xaKnqO8NYT2ZmyvpM,1056
typish-1.9.3.dist-info/METADATA,sha256=UzXbrF6I-7cD_3IDIVx6X3iXCfskHxgm3_a6iWzJVfs,7162
typish-1.9.3.dist-info/RECORD,,
typish-1.9.3.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
typish-1.9.3.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
typish-1.9.3.dist-info/direct_url.json,sha256=jAQ_UflMFbK-w0TDkKwiqAJARiFKlweE70HgXbPFNhg,102
typish-1.9.3.dist-info/top_level.txt,sha256=0d-LkM00cwkivwIHZ1NLYezetVHCuNtlkpXtZqvPdsk,7
typish/__init__.py,sha256=IEQ82ACBTCDA1G4Cr_nRfLr7nONo52UHYjNKKaVEwnA,1448
typish/__pycache__/__init__.cpython-39.pyc,,
typish/__pycache__/_meta.cpython-39.pyc,,
typish/__pycache__/_state.cpython-39.pyc,,
typish/__pycache__/_types.cpython-39.pyc,,
typish/_meta.py,sha256=1wqQn0T4bMijmcpBK1Y5Ki_RZfXMFO_ArARwBwuPq-Q,238
typish/_state.py,sha256=709JwS2gZhmNRdNlD4FATVHXUxyprGHdaPsTZzxQ4eE,1256
typish/_types.py,sha256=oC8YNu4Ftzv45_rDmSbOAMIvEhSxjOYJUPfNl0ZgMhg,428
typish/classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
typish/classes/__pycache__/__init__.cpython-39.pyc,,
typish/classes/__pycache__/_cls_dict.cpython-39.pyc,,
typish/classes/__pycache__/_cls_function.cpython-39.pyc,,
typish/classes/__pycache__/_literal.cpython-39.pyc,,
typish/classes/__pycache__/_something.cpython-39.pyc,,
typish/classes/__pycache__/_subscriptable_type.cpython-39.pyc,,
typish/classes/__pycache__/_union_type.cpython-39.pyc,,
typish/classes/_cls_dict.py,sha256=HP3vjoeZhjHtGwaMxqMr3VzzdB_3Y1XPB5FbM9x3kYU,1888
typish/classes/_cls_function.py,sha256=L6mCf5bE5UKRxifr4N4wr7gaXsVDU2tYMfxLYgYF_gU,2921
typish/classes/_literal.py,sha256=nJRuSUbKlJrbRv4Cn5KCPE94mBpZaXgZ8xpYndUNXlg,2530
typish/classes/_something.py,sha256=RjsV5KkzcMBtwEY7g76QzQbroQFi5dybW1xAULH9lPQ,4767
typish/classes/_subscriptable_type.py,sha256=_0KcWwT_pmMaZd7cD4p0LKJ5J1L75vVaC3lhOAEV3ZQ,1580
typish/classes/_union_type.py,sha256=KUykLiNlGfzDqNhGsfMP9aCQe1SAewg8kO6g32eDl5w,178
typish/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
typish/decorators/__pycache__/__init__.cpython-39.pyc,,
typish/decorators/__pycache__/_hintable.cpython-39.pyc,,
typish/decorators/_hintable.py,sha256=aue96q_iCbfUG46bBmPFa3cPS5NbGQrmpnj1MiWaaTE,3864
typish/functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
typish/functions/__pycache__/__init__.cpython-39.pyc,,
typish/functions/__pycache__/_common_ancestor.cpython-39.pyc,,
typish/functions/__pycache__/_get_alias.cpython-39.pyc,,
typish/functions/__pycache__/_get_args.cpython-39.pyc,,
typish/functions/__pycache__/_get_mro.cpython-39.pyc,,
typish/functions/__pycache__/_get_origin.cpython-39.pyc,,
typish/functions/__pycache__/_get_simple_name.cpython-39.pyc,,
typish/functions/__pycache__/_get_type.cpython-39.pyc,,
typish/functions/__pycache__/_get_type_hints_of_callable.cpython-39.pyc,,
typish/functions/__pycache__/_instance_of.cpython-39.pyc,,
typish/functions/__pycache__/_is_from_typing.cpython-39.pyc,,
typish/functions/__pycache__/_is_optional_type.cpython-39.pyc,,
typish/functions/__pycache__/_is_type_annotation.cpython-39.pyc,,
typish/functions/__pycache__/_subclass_of.cpython-39.pyc,,
typish/functions/_common_ancestor.py,sha256=IAJ7hUkMQPI7xzJSGePzBreFQvGHKfj8-lL6eoR4MOE,1137
typish/functions/_get_alias.py,sha256=xemVuuzQS8Kw5Yt8HR1zL29U6brldLBT7OQdkCZeY_0,1195
typish/functions/_get_args.py,sha256=544sdnK7OavcLhfeezRlPTPTu33maI9J_OrTtuilxjE,417
typish/functions/_get_mro.py,sha256=2rQiXWOf4rXDuMka6g7I2pSajSoXj3KjVtccSWIHZXk,910
typish/functions/_get_origin.py,sha256=SSJZjyweg1cHHY5J4xvnuPO5T-K7P34XyC7M1u7vmAI,1114
typish/functions/_get_simple_name.py,sha256=a61cjPmQ5h8ERkduU4VUdLRjvzZ7pdfVjZVLYsAq4FI,536
typish/functions/_get_type.py,sha256=NwMXSUSiU0R9kuyZ23r6Ux_itRQos_iNUteqJ0v2Roo,4450
typish/functions/_get_type_hints_of_callable.py,sha256=qU271x5JTmnUquz6ONWKfkHaNNxfuc1PAsLT-JuuZFs,1583
typish/functions/_instance_of.py,sha256=0a9eGbH_GFhhamVKd1bh2jVzofTVLBl8t_XCiiCsptg,1498
typish/functions/_is_from_typing.py,sha256=6pbcf7uLgMo5yJmOg9enKxg5iOR4PCFmVChYd3wMcP8,243
typish/functions/_is_optional_type.py,sha256=E7V1E_JjrJ6Hdl6CYQCQc_CmjsR1lbaQsV5ri5iqpbo,625
typish/functions/_is_type_annotation.py,sha256=rEUhdQ7nIZFHmRhPUpbCnDOObPrQoJFV7-8IE-VuCLc,852
typish/functions/_subclass_of.py,sha256=3ha-TcBj6Xb1bm2T6Nn7nFrvUy1HDX6PkdEgXDuQHQE,5709

View File

@@ -0,0 +1,5 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.36.2)
Root-Is-Purelib: true
Tag: py3-none-any

View File

@@ -0,0 +1 @@
{"dir_info": {}, "url": "file:///home/conda/feedstock_root/build_artifacts/typish_1628254486386/work"}

View File

@@ -0,0 +1 @@
typish