diff --git a/CHANGELOG.md b/CHANGELOG.md index c447d70..029536c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/pedantic/mixins/with_decorated_methods.html b/docs/pedantic/mixins/with_decorated_methods.html index 123c874..2864e1d 100644 --- a/docs/pedantic/mixins/with_decorated_methods.html +++ b/docs/pedantic/mixins/with_decorated_methods.html @@ -52,7 +52,7 @@

Module pedantic.mixins.with_decorated_methods

Module pedantic.mixins.with_decorated_methodsModule pedantic.mixins.with_decorated_methodsFunctions
-def create_decorator(decorator_type: DecoratorType, transformation: Callable[[~C], ~C] = None) ‑> Callable[[~T], Callable[[~C], ~C]] +def create_decorator(decorator_type: DecoratorType, 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. @@ -143,7 +143,7 @@

Functions

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.
@@ -157,7 +157,7 @@ 

Functions

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 diff --git a/docs/pedantic/tests/test_with_decorated_methods.html b/docs/pedantic/tests/test_with_decorated_methods.html index 9427f71..098f36a 100644 --- a/docs/pedantic/tests/test_with_decorated_methods.html +++ b/docs/pedantic/tests/test_with_decorated_methods.html @@ -96,7 +96,10 @@

Module pedantic.tests.test_with_decorated_methods 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) @@ -264,7 +267,10 @@

Class variables

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) @@ -306,7 +312,10 @@

Methods

Expand source 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)
diff --git a/pedantic/mixins/with_decorated_methods.py b/pedantic/mixins/with_decorated_methods.py
index 3ab8f0d..9c7826c 100644
--- a/pedantic/mixins/with_decorated_methods.py
+++ b/pedantic/mixins/with_decorated_methods.py
@@ -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.
@@ -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
 
diff --git a/pedantic/tests/test_with_decorated_methods.py b/pedantic/tests/test_with_decorated_methods.py
index a1744b8..b095712 100644
--- a/pedantic/tests/test_with_decorated_methods.py
+++ b/pedantic/tests/test_with_decorated_methods.py
@@ -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)
diff --git a/setup.py b/setup.py
index 0d629f1..522043b 100644
--- a/setup.py
+++ b/setup.py
@@ -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=[],