Skip to content

Commit

Permalink
Feature/add decorators (#66)
Browse files Browse the repository at this point in the history
* added in_subprocess decorator

* added GenericMixin and in_subprocess decorator

* try to fix tests

* disabled CI Job for Python 3.11

* improve test coverage
  • Loading branch information
LostInDarkMath committed Oct 16, 2022
1 parent 809f289 commit 09bdc7a
Show file tree
Hide file tree
Showing 30 changed files with 2,079 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python: # https://docs.travis-ci.com/user/languages/python/#python-versions
- "3.8"
- "3.9"
- "3.10.2"
- "3.11-dev"
# - "3.11-dev" # temporarily disabled because it stucks in CI

branches:
only:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## Pedantic 1.13.0
- added `GenericMixin`
- added `@in_subprocess` decorator

## Pedantic 1.12.11
- bugfix in type checking logic

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def my_algorithm(value: float, config: Configuration) -> float:
This method calculates something that depends on the given value with considering the configuration.
Note how well this small piece of code is designed:
- Fhe function my_algorithm() need a Configuration but has no knowledge where this come from.
- Furthermore, it need does not care about parameter validation.
- The ConfigurationValidator doesn't now anything about the creation of the data.
- Furthermore, it doesn't care about parameter validation.
- The ConfigurationValidator doesn't know anything about the creation of the data.
- The @validate decorator is the only you need to change, if you want a different configuration source.
"""
print(value)
Expand All @@ -160,6 +160,7 @@ if __name__ == '__main__':
- [@frozen_dataclass](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/cls_deco_frozen_dataclass.html#pedantic.decorators.cls_deco_frozen_dataclass.frozen_dataclass)
- [@frozen_type_safe_dataclass](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/cls_deco_frozen_dataclass.html#pedantic.decorators.cls_deco_frozen_dataclass.frozen_type_safe_dataclass)
- [@for_all_methods](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/class_decorators.html#pedantic.decorators.class_decorators.for_all_methods)
- [@in_subprocess](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/fn_deco_in_subprocess.html)
- [@mock](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/fn_deco_mock.html)
- [@overrides](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/fn_deco_overrides.html)
- [@pedantic](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/fn_deco_pedantic.html#pedantic.decorators.fn_deco_pedantic.pedantic)
Expand All @@ -176,10 +177,14 @@ if __name__ == '__main__':
- [@unimplemented](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/fn_deco_unimplemented.html)
- [@validate](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/decorators/fn_deco_validate/fn_deco_validate.html)

## List of all mixins in this package
- [GenericMixin](https://lostindarkmath.github.io/pedantic-python-decorators/pedantic/mxins/generic_mixin.html)

## Dependencies
There are no hard dependencies. But if you want to use some advanced features you need to install the following packages:
- [Docstring-Parser](https://github.com/rr-/docstring_parser) if you need to verify your docstrings.
- [flask](https://pypi.org/project/Flask/) if want to you the request validators which are designed for `Flask` (see unit tests for examples):
- [multiprocess](https://github.com/uqfoundation/multiprocess) if you want to use the `@in_subprocess` decorator
- [flask](https://pypi.org/project/Flask/) if you want to you the request validators which are designed for `Flask` (see unit tests for examples):
- `FlaskParameter` (abstract class)
- `FlaskJsonParameter`
- `FlaskFormParameter`
Expand Down
323 changes: 323 additions & 0 deletions docs/pedantic/decorators/fn_deco_in_subprocess.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/pedantic/decorators/fn_deco_overrides.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1 class="title">Module <code>pedantic.decorators.fn_deco_overrides</code></h1>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="pedantic.decorators.fn_deco_overrides.overrides"><code class="name flex">
<span>def <span class="ident">overrides</span></span>(<span>base_class: Type) ‑> Callable[..., ~ReturnType]</span>
<span>def <span class="ident">overrides</span></span>(<span>base_class: Type[+CT_co]) ‑> Callable[..., ~ReturnType]</span>
</code></dt>
<dd>
<div class="desc"><p>This is used for marking methods that overrides methods of the base class which makes the code more readable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h3>Ancestors</h3>
<h3>Methods</h3>
<dl>
<dt id="pedantic.decorators.fn_deco_validate.validators.not_empty.NotEmpty.validate"><code class="name flex">
<span>def <span class="ident">validate</span></span>(<span>self, value: Sequence) ‑> Sequence</span>
<span>def <span class="ident">validate</span></span>(<span>self, value: Sequence[+T_co]) ‑> Sequence[+T_co]</span>
</code></dt>
<dd>
<div class="desc"><p>Throws a ValidationError if the sequence is empty.
Expand Down
6 changes: 6 additions & 0 deletions docs/pedantic/decorators/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ <h1 class="title">Module <code>pedantic.decorators</code></h1>
<pre><code class="python">from .fn_deco_count_calls import count_calls
from .fn_deco_deprecated import deprecated
from .fn_deco_does_same_as_function import does_same_as_function
from .fn_deco_in_subprocess import in_subprocess, calculate_in_subprocess
from .fn_deco_mock import mock
from .fn_deco_overrides import overrides
from .fn_deco_pedantic import pedantic, pedantic_require_docstring
Expand Down Expand Up @@ -66,6 +67,10 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="pedantic.decorators.fn_deco_in_subprocess" href="fn_deco_in_subprocess.html">pedantic.decorators.fn_deco_in_subprocess</a></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="pedantic.decorators.fn_deco_mock" href="fn_deco_mock.html">pedantic.decorators.fn_deco_mock</a></code></dt>
<dd>
<div class="desc"></div>
Expand Down Expand Up @@ -133,6 +138,7 @@ <h1>Index</h1>
<li><code><a title="pedantic.decorators.fn_deco_count_calls" href="fn_deco_count_calls.html">pedantic.decorators.fn_deco_count_calls</a></code></li>
<li><code><a title="pedantic.decorators.fn_deco_deprecated" href="fn_deco_deprecated.html">pedantic.decorators.fn_deco_deprecated</a></code></li>
<li><code><a title="pedantic.decorators.fn_deco_does_same_as_function" href="fn_deco_does_same_as_function.html">pedantic.decorators.fn_deco_does_same_as_function</a></code></li>
<li><code><a title="pedantic.decorators.fn_deco_in_subprocess" href="fn_deco_in_subprocess.html">pedantic.decorators.fn_deco_in_subprocess</a></code></li>
<li><code><a title="pedantic.decorators.fn_deco_mock" href="fn_deco_mock.html">pedantic.decorators.fn_deco_mock</a></code></li>
<li><code><a title="pedantic.decorators.fn_deco_overrides" href="fn_deco_overrides.html">pedantic.decorators.fn_deco_overrides</a></code></li>
<li><code><a title="pedantic.decorators.fn_deco_pedantic" href="fn_deco_pedantic.html">pedantic.decorators.fn_deco_pedantic</a></code></li>
Expand Down
3 changes: 1 addition & 2 deletions docs/pedantic/examples/validate.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ <h3>Inherited members</h3>
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@dataclass(frozen=True)
class Configuration:
<pre><code class="python">class Configuration:
iterations: int
max_error: float</code></pre>
</details>
Expand Down
10 changes: 9 additions & 1 deletion docs/pedantic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ <h1 class="title">Package <code>pedantic</code></h1>
from pedantic.decorators import overrides, rename_kwargs, timer, count_calls, trace, trace_if_returns, \
does_same_as_function, deprecated, unimplemented, require_kwargs, pedantic, \
pedantic_require_docstring, for_all_methods, trace_class, timer_class, pedantic_class, \
pedantic_class_require_docstring, Rename, mock, frozen_dataclass, frozen_type_safe_dataclass
pedantic_class_require_docstring, Rename, mock, frozen_dataclass, frozen_type_safe_dataclass, in_subprocess, \
calculate_in_subprocess

from pedantic.mixins import GenericMixin

from pedantic.exceptions import NotImplementedException

Expand Down Expand Up @@ -72,6 +75,10 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="pedantic.mixins" href="mixins/index.html">pedantic.mixins</a></code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt><code class="name"><a title="pedantic.models" href="models/index.html">pedantic.models</a></code></dt>
<dd>
<div class="desc"></div>
Expand Down Expand Up @@ -107,6 +114,7 @@ <h1>Index</h1>
<li><code><a title="pedantic.examples" href="examples/index.html">pedantic.examples</a></code></li>
<li><code><a title="pedantic.exceptions" href="exceptions.html">pedantic.exceptions</a></code></li>
<li><code><a title="pedantic.helper_methods" href="helper_methods.html">pedantic.helper_methods</a></code></li>
<li><code><a title="pedantic.mixins" href="mixins/index.html">pedantic.mixins</a></code></li>
<li><code><a title="pedantic.models" href="models/index.html">pedantic.models</a></code></li>
<li><code><a title="pedantic.tests" href="tests/index.html">pedantic.tests</a></code></li>
<li><code><a title="pedantic.type_checking_logic" href="type_checking_logic/index.html">pedantic.type_checking_logic</a></code></li>
Expand Down
Loading

0 comments on commit 09bdc7a

Please sign in to comment.