summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--python-runtype.spec326
-rw-r--r--sources1
3 files changed, 328 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..d649f15 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/runtype-0.3.2.tar.gz
diff --git a/python-runtype.spec b/python-runtype.spec
new file mode 100644
index 0000000..6b5d2a5
--- /dev/null
+++ b/python-runtype.spec
@@ -0,0 +1,326 @@
+%global _empty_manifest_terminate_build 0
+Name: python-runtype
+Version: 0.3.2
+Release: 1
+Summary: Type dispatch and validation for run-time Python
+License: MIT
+URL: https://github.com/erezsh/runtype
+Source0: https://mirrors.aliyun.com/pypi/web/packages/4f/db/19c89912496398cef02d634804176d60f3eb464ea48812b2c1ee1cbf0c0a/runtype-0.3.2.tar.gz
+BuildArch: noarch
+
+Requires: python3-dataclasses
+Requires: python3-contextvars
+
+%description
+### Modules
+- :star: [**validation**](https://runtype.readthedocs.io/en/latest/validation.html) - Provides a smarter alternative to `isinstance` and `issubclass`, with support for the `typing` module, and type constraints.
+- :star: [**dataclass**](https://runtype.readthedocs.io/en/latest/dataclass.html) - Adds run-time type validation to the built-in dataclass.
+ - Improves dataclass ergonomics.
+ - Supports most mypy constructs, like `typing` and forward-references (`foo: 'Bar'`).
+ - Supports automatic value casting, Pydantic-style. (Optional, off by default)
+ - Supports types with constraints. (e.g. `String(max_length=10)`)
+ - Supports optional sampling for faster validation of big lists and dicts.
+ - Twice faster than Pydantic ([read here](https://runtype.readthedocs.io/en/latest/dataclass.html#compared-to-pydantic))
+- :star: [**dispatch**](https://runtype.readthedocs.io/en/latest/dispatch.html) - Provides fast multiple-dispatch for functions and methods, via a decorator.
+ - Inspired by Julia.
+- :star: [**type utilities**](https://runtype.readthedocs.io/en/latest/types.html) - Provides a set of classes to implement your own type-system.
+ - Used by runtype itself, to emulate the Python type-system.
+## Docs
+Read the docs here: https://runtype.readthedocs.io/
+## Install
+```bash
+pip install runtype
+```
+No dependencies.
+Requires Python 3.6 or up.
+[![Build Status](https://travis-ci.org/erezsh/runtype.svg?branch=master)](https://travis-ci.org/erezsh/runtype)
+[![codecov](https://codecov.io/gh/erezsh/runtype/branch/master/graph/badge.svg)](https://codecov.io/gh/erezsh/runtype)
+## Examples
+### Validation (Isa & Subclass)
+```python
+from typing import Dict, Mapping
+from runtype import isa, issubclass
+print( isa({'a': 1}, Dict[str, int]) )
+#> True
+print( isa({'a': 'b'}, Dict[str, int]) )
+#> False
+print( issubclass(Dict[str, int], Mapping[str, int]) )
+#> True
+print( issubclass(Dict[str, int], Mapping[int, str]) )
+#> False
+```
+### Dataclasses
+```python
+from typing import List
+from datetime import datetime
+from runtype import dataclass
+@dataclass(check_types='cast') # Cast values to the target type, when applicable
+class Person:
+ name: str
+ birthday: datetime = None # Optional
+ interests: List[str] = [] # The list is copied for each instance
+print( Person("Beetlejuice") )
+#> Person(name='Beetlejuice', birthday=None, interests=[])
+print( Person("Albert", "1955-04-18T00:00", ['physics']) )
+#> Person(name='Albert', birthday=datetime.datetime(1955, 4, 18, 0, 0), interests=['physics'])
+print( Person("Bad", interests=['a', 1]) )
+# Traceback (most recent call last):
+# ...
+# TypeError: [Person] Attribute 'interests' expected value of type list[str]. Instead got ['a', 1]
+# Failed on item: 1, expected type str
+```
+### Multiple Dispatch
+```python
+from runtype import Dispatch
+dp = Dispatch()
+@dp
+def append(a: list, b):
+ return a + [b]
+@dp
+def append(a: tuple, b):
+ return a + (b,)
+@dp
+def append(a: str, b: str):
+ return a + b
+print( append([1, 2, 3], 4) )
+#> [1, 2, 3, 4]
+print( append((1, 2, 3), 4) )
+#> (1, 2, 3, 4)
+print( append('foo', 'bar') )
+#> foobar
+print( append('foo', 4) )
+# Traceback (most recent call last):
+# ...
+# runtype.dispatch.DispatchError: Function 'append' not found for signature (<class 'str'>, <class 'int'>)
+```
+## License
+Runtype uses the [MIT license](LICENSE).
+## Donate
+If you like Runtype and want to show your appreciation, you can do so at my [patreon page](https://www.patreon.com/erezsh), or [ko-fi page](https://ko-fi.com/erezsh).
+
+%package -n python3-runtype
+Summary: Type dispatch and validation for run-time Python
+Provides: python-runtype
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-runtype
+### Modules
+- :star: [**validation**](https://runtype.readthedocs.io/en/latest/validation.html) - Provides a smarter alternative to `isinstance` and `issubclass`, with support for the `typing` module, and type constraints.
+- :star: [**dataclass**](https://runtype.readthedocs.io/en/latest/dataclass.html) - Adds run-time type validation to the built-in dataclass.
+ - Improves dataclass ergonomics.
+ - Supports most mypy constructs, like `typing` and forward-references (`foo: 'Bar'`).
+ - Supports automatic value casting, Pydantic-style. (Optional, off by default)
+ - Supports types with constraints. (e.g. `String(max_length=10)`)
+ - Supports optional sampling for faster validation of big lists and dicts.
+ - Twice faster than Pydantic ([read here](https://runtype.readthedocs.io/en/latest/dataclass.html#compared-to-pydantic))
+- :star: [**dispatch**](https://runtype.readthedocs.io/en/latest/dispatch.html) - Provides fast multiple-dispatch for functions and methods, via a decorator.
+ - Inspired by Julia.
+- :star: [**type utilities**](https://runtype.readthedocs.io/en/latest/types.html) - Provides a set of classes to implement your own type-system.
+ - Used by runtype itself, to emulate the Python type-system.
+## Docs
+Read the docs here: https://runtype.readthedocs.io/
+## Install
+```bash
+pip install runtype
+```
+No dependencies.
+Requires Python 3.6 or up.
+[![Build Status](https://travis-ci.org/erezsh/runtype.svg?branch=master)](https://travis-ci.org/erezsh/runtype)
+[![codecov](https://codecov.io/gh/erezsh/runtype/branch/master/graph/badge.svg)](https://codecov.io/gh/erezsh/runtype)
+## Examples
+### Validation (Isa & Subclass)
+```python
+from typing import Dict, Mapping
+from runtype import isa, issubclass
+print( isa({'a': 1}, Dict[str, int]) )
+#> True
+print( isa({'a': 'b'}, Dict[str, int]) )
+#> False
+print( issubclass(Dict[str, int], Mapping[str, int]) )
+#> True
+print( issubclass(Dict[str, int], Mapping[int, str]) )
+#> False
+```
+### Dataclasses
+```python
+from typing import List
+from datetime import datetime
+from runtype import dataclass
+@dataclass(check_types='cast') # Cast values to the target type, when applicable
+class Person:
+ name: str
+ birthday: datetime = None # Optional
+ interests: List[str] = [] # The list is copied for each instance
+print( Person("Beetlejuice") )
+#> Person(name='Beetlejuice', birthday=None, interests=[])
+print( Person("Albert", "1955-04-18T00:00", ['physics']) )
+#> Person(name='Albert', birthday=datetime.datetime(1955, 4, 18, 0, 0), interests=['physics'])
+print( Person("Bad", interests=['a', 1]) )
+# Traceback (most recent call last):
+# ...
+# TypeError: [Person] Attribute 'interests' expected value of type list[str]. Instead got ['a', 1]
+# Failed on item: 1, expected type str
+```
+### Multiple Dispatch
+```python
+from runtype import Dispatch
+dp = Dispatch()
+@dp
+def append(a: list, b):
+ return a + [b]
+@dp
+def append(a: tuple, b):
+ return a + (b,)
+@dp
+def append(a: str, b: str):
+ return a + b
+print( append([1, 2, 3], 4) )
+#> [1, 2, 3, 4]
+print( append((1, 2, 3), 4) )
+#> (1, 2, 3, 4)
+print( append('foo', 'bar') )
+#> foobar
+print( append('foo', 4) )
+# Traceback (most recent call last):
+# ...
+# runtype.dispatch.DispatchError: Function 'append' not found for signature (<class 'str'>, <class 'int'>)
+```
+## License
+Runtype uses the [MIT license](LICENSE).
+## Donate
+If you like Runtype and want to show your appreciation, you can do so at my [patreon page](https://www.patreon.com/erezsh), or [ko-fi page](https://ko-fi.com/erezsh).
+
+%package help
+Summary: Development documents and examples for runtype
+Provides: python3-runtype-doc
+%description help
+### Modules
+- :star: [**validation**](https://runtype.readthedocs.io/en/latest/validation.html) - Provides a smarter alternative to `isinstance` and `issubclass`, with support for the `typing` module, and type constraints.
+- :star: [**dataclass**](https://runtype.readthedocs.io/en/latest/dataclass.html) - Adds run-time type validation to the built-in dataclass.
+ - Improves dataclass ergonomics.
+ - Supports most mypy constructs, like `typing` and forward-references (`foo: 'Bar'`).
+ - Supports automatic value casting, Pydantic-style. (Optional, off by default)
+ - Supports types with constraints. (e.g. `String(max_length=10)`)
+ - Supports optional sampling for faster validation of big lists and dicts.
+ - Twice faster than Pydantic ([read here](https://runtype.readthedocs.io/en/latest/dataclass.html#compared-to-pydantic))
+- :star: [**dispatch**](https://runtype.readthedocs.io/en/latest/dispatch.html) - Provides fast multiple-dispatch for functions and methods, via a decorator.
+ - Inspired by Julia.
+- :star: [**type utilities**](https://runtype.readthedocs.io/en/latest/types.html) - Provides a set of classes to implement your own type-system.
+ - Used by runtype itself, to emulate the Python type-system.
+## Docs
+Read the docs here: https://runtype.readthedocs.io/
+## Install
+```bash
+pip install runtype
+```
+No dependencies.
+Requires Python 3.6 or up.
+[![Build Status](https://travis-ci.org/erezsh/runtype.svg?branch=master)](https://travis-ci.org/erezsh/runtype)
+[![codecov](https://codecov.io/gh/erezsh/runtype/branch/master/graph/badge.svg)](https://codecov.io/gh/erezsh/runtype)
+## Examples
+### Validation (Isa & Subclass)
+```python
+from typing import Dict, Mapping
+from runtype import isa, issubclass
+print( isa({'a': 1}, Dict[str, int]) )
+#> True
+print( isa({'a': 'b'}, Dict[str, int]) )
+#> False
+print( issubclass(Dict[str, int], Mapping[str, int]) )
+#> True
+print( issubclass(Dict[str, int], Mapping[int, str]) )
+#> False
+```
+### Dataclasses
+```python
+from typing import List
+from datetime import datetime
+from runtype import dataclass
+@dataclass(check_types='cast') # Cast values to the target type, when applicable
+class Person:
+ name: str
+ birthday: datetime = None # Optional
+ interests: List[str] = [] # The list is copied for each instance
+print( Person("Beetlejuice") )
+#> Person(name='Beetlejuice', birthday=None, interests=[])
+print( Person("Albert", "1955-04-18T00:00", ['physics']) )
+#> Person(name='Albert', birthday=datetime.datetime(1955, 4, 18, 0, 0), interests=['physics'])
+print( Person("Bad", interests=['a', 1]) )
+# Traceback (most recent call last):
+# ...
+# TypeError: [Person] Attribute 'interests' expected value of type list[str]. Instead got ['a', 1]
+# Failed on item: 1, expected type str
+```
+### Multiple Dispatch
+```python
+from runtype import Dispatch
+dp = Dispatch()
+@dp
+def append(a: list, b):
+ return a + [b]
+@dp
+def append(a: tuple, b):
+ return a + (b,)
+@dp
+def append(a: str, b: str):
+ return a + b
+print( append([1, 2, 3], 4) )
+#> [1, 2, 3, 4]
+print( append((1, 2, 3), 4) )
+#> (1, 2, 3, 4)
+print( append('foo', 'bar') )
+#> foobar
+print( append('foo', 4) )
+# Traceback (most recent call last):
+# ...
+# runtype.dispatch.DispatchError: Function 'append' not found for signature (<class 'str'>, <class 'int'>)
+```
+## License
+Runtype uses the [MIT license](LICENSE).
+## Donate
+If you like Runtype and want to show your appreciation, you can do so at my [patreon page](https://www.patreon.com/erezsh), or [ko-fi page](https://ko-fi.com/erezsh).
+
+%prep
+%autosetup -n runtype-0.3.2
+
+%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-runtype -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.3.2-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..9eea4f2
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+95f2d7a5f0adc5face5796702bd90e15 runtype-0.3.2.tar.gz