Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## Pedantic 2.1.8
- add more parameters to `transformation` in `create_decorator` to make it more flexible

## Pedantic 2.1.7
- add `transformation` parameter to `create_decorator` to make adding custom behavior easier

Expand Down
10 changes: 5 additions & 5 deletions docs/pedantic/mixins/with_decorated_methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h1 class="title">Module <code>pedantic.mixins.with_decorated_methods</code></h1

def create_decorator(
decorator_type: DecoratorType,
transformation: Callable[[C], C] = None,
transformation: Callable[[C, DecoratorType, T], C] = None,
) -&gt; Callable[[T], Callable[[C], C]]:
&#34;&#34;&#34;
Creates a new decorator that is parametrized with one argument of an arbitrary type.
Expand All @@ -66,7 +66,7 @@ <h1 class="title">Module <code>pedantic.mixins.with_decorated_methods</code></h1
if transformation is None:
return f

return transformation(f)
return transformation(f, decorator_type, value)

return fun # we do not need functools.wraps, because we return the original function here

Expand Down Expand Up @@ -132,7 +132,7 @@ <h1 class="title">Module <code>pedantic.mixins.with_decorated_methods</code></h1
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="pedantic.mixins.with_decorated_methods.create_decorator"><code class="name flex">
<span>def <span class="ident">create_decorator</span></span>(<span>decorator_type: <a title="pedantic.mixins.with_decorated_methods.DecoratorType" href="#pedantic.mixins.with_decorated_methods.DecoratorType">DecoratorType</a>, transformation: Callable[[~C], ~C] = None) ‑> Callable[[~T], Callable[[~C], ~C]]</span>
<span>def <span class="ident">create_decorator</span></span>(<span>decorator_type: <a title="pedantic.mixins.with_decorated_methods.DecoratorType" href="#pedantic.mixins.with_decorated_methods.DecoratorType">DecoratorType</a>, transformation: Callable[[~C, <a title="pedantic.mixins.with_decorated_methods.DecoratorType" href="#pedantic.mixins.with_decorated_methods.DecoratorType">DecoratorType</a>, ~T], ~C] = None) ‑> Callable[[~T], Callable[[~C], ~C]]</span>
</code></dt>
<dd>
<div class="desc"><p>Creates a new decorator that is parametrized with one argument of an arbitrary type.
Expand All @@ -143,7 +143,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</summary>
<pre><code class="python">def create_decorator(
decorator_type: DecoratorType,
transformation: Callable[[C], C] = None,
transformation: Callable[[C, DecoratorType, T], C] = None,
) -&gt; Callable[[T], Callable[[C], C]]:
&#34;&#34;&#34;
Creates a new decorator that is parametrized with one argument of an arbitrary type.
Expand All @@ -157,7 +157,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
if transformation is None:
return f

return transformation(f)
return transformation(f, decorator_type, value)

return fun # we do not need functools.wraps, because we return the original function here

Expand Down
15 changes: 12 additions & 3 deletions docs/pedantic/tests/test_with_decorated_methods.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ <h1 class="title">Module <code>pedantic.tests.test_with_decorated_methods</code>


def test_with_custom_transformation(self):
def my_transformation(f):
def my_transformation(f, decorator_type, value):
assert decorator_type == Decorators.BAR
assert value == 42

@wraps(f)
def wrapper(*args, **kwargs):
f(*args, **kwargs)
Expand Down Expand Up @@ -264,7 +267,10 @@ <h3>Class variables</h3>


def test_with_custom_transformation(self):
def my_transformation(f):
def my_transformation(f, decorator_type, value):
assert decorator_type == Decorators.BAR
assert value == 42

@wraps(f)
def wrapper(*args, **kwargs):
f(*args, **kwargs)
Expand Down Expand Up @@ -306,7 +312,10 @@ <h3>Methods</h3>
<span>Expand source code</span>
</summary>
<pre><code class="python">def test_with_custom_transformation(self):
def my_transformation(f):
def my_transformation(f, decorator_type, value):
assert decorator_type == Decorators.BAR
assert value == 42

@wraps(f)
def wrapper(*args, **kwargs):
f(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions pedantic/mixins/with_decorated_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DecoratorType(StrEnum):

def create_decorator(
decorator_type: DecoratorType,
transformation: Callable[[C], C] = None,
transformation: Callable[[C, DecoratorType, T], C] = None,
) -> Callable[[T], Callable[[C], C]]:
"""
Creates a new decorator that is parametrized with one argument of an arbitrary type.
Expand All @@ -38,7 +38,7 @@ def fun(f: C) -> C:
if transformation is None:
return f

return transformation(f)
return transformation(f, decorator_type, value)

return fun # we do not need functools.wraps, because we return the original function here

Expand Down
5 changes: 4 additions & 1 deletion pedantic/tests/test_with_decorated_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ async def m3(self) -> None:


def test_with_custom_transformation(self):
def my_transformation(f):
def my_transformation(f, decorator_type, value):
assert decorator_type == Decorators.BAR
assert value == 42

@wraps(f)
def wrapper(*args, **kwargs):
f(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_content_from_readme(file_name: str = 'README.md') -> str:

setup(
name="pedantic",
version="2.1.7",
version="2.1.8",
python_requires='>=3.11.0',
packages=find_packages(),
install_requires=[],
Expand Down
Loading