summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2021-04-03 15:57:33 +0200
committerMichele Simionato <michele.simionato@gmail.com>2021-04-03 15:57:33 +0200
commit7fb1e34632b8f27578eb89c1c583c58b7dc74fde (patch)
tree2d4fa4b223d8db51a755ecb6df9aa645ded0810e
parentc12ec8557d8834e4c5c7c59b8275f3694ea6039d (diff)
downloadpython-decorator-git-7fb1e34632b8f27578eb89c1c583c58b7dc74fde.tar.gz
Fixed func.__doc__ not being copied
-rw-r--r--CHANGES.md7
-rw-r--r--docs/documentation.md8
-rw-r--r--src/decorator.py17
-rw-r--r--src/tests/documentation.py4
4 files changed, 16 insertions, 20 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 20a78fa..8077af3 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -3,7 +3,12 @@ HISTORY
## unreleased
-## 5.0.0 (2021-04-02)
+## 5.0.4 (2021-04-03)
+
+Small fix (decorator.decorate was not copying the function docstring) and
+documented the breaking change between versions 5.X and the past.
+
+## 5.0.3 (2021-04-02)
Dropped support for Python < 3.5 with a substantial simplification of
the code base. Ported CI from Travis to GitHub.
diff --git a/docs/documentation.md b/docs/documentation.md
index 1baa757..9d7ad9c 100644
--- a/docs/documentation.md
+++ b/docs/documentation.md
@@ -4,9 +4,9 @@ Decorators for Humans
|Author | Michele Simionato|
|---|---|
|E-mail | michele.simionato@gmail.com|
-|Version| 5.0.3 (2021-04-03)|
+|Version| 5.0.4 (2021-04-03)|
|Supports| Python 3.5, 3.6, 3.7, 3.8, 3.9|
-|Download page| http://pypi.python.org/pypi/decorator/5.0.3|
+|Download page| http://pypi.python.org/pypi/decorator/5.0.4|
|Installation| ``pip install decorator``|
|License | BSD license|
@@ -1505,7 +1505,7 @@ and not if you pass them as keyword arguments:
```
This can be pretty confusing since non-keyword arguments are passed as
keywork arguments, but it the way it works with ``functools.wraps`` and
-the way many people expect it to work:
+the way many people expect it to work. You can play with
```python
@@ -1517,6 +1517,8 @@ the way many people expect it to work:
return functools.wraps(wrapper)
```
+and see that we are consistent indeed.
+
In the present implementation, decorators generated by ``decorator``
can only be used on user-defined Python functions, methods or coroutines.
I have no interest in decorating generic callable objects. If you want to
diff --git a/src/decorator.py b/src/decorator.py
index 465558f..1cb1596 100644
--- a/src/decorator.py
+++ b/src/decorator.py
@@ -37,11 +37,10 @@ import sys
import inspect
import operator
import itertools
-import abc
from contextlib import _GeneratorContextManager
from inspect import getfullargspec, iscoroutinefunction, isgeneratorfunction
-__version__ = '5.0.3'
+__version__ = '5.0.4'
DEF = re.compile(r'\s*def\s*([_\w][_\w\d]*)\s*\(')
POS = inspect.Parameter.POSITIONAL_OR_KEYWORD
@@ -219,23 +218,11 @@ def decorate(func, caller, extras=()):
fun.__qualname__ = func.__qualname__
fun.__annotations__ = func.__annotations__
fun.__kwdefaults__ = func.__kwdefaults__
+ fun.__doc__ = func.__doc__
fun.__dict__.update(func.__dict__)
return fun
-class Decorator(metaclass=abc.ABCMeta):
- """
- Abstract base class. Subclass it and override the caller method to
- define your own decorator factories.
- """
- @abc.abstractmethod
- def caller(self, func, *args, **kw):
- pass
-
- def __call__(self, func):
- return decorate(func, self.caller)
-
-
def decorator(caller, _func=None):
"""
decorator(caller) converts a caller function into a decorator
diff --git a/src/tests/documentation.py b/src/tests/documentation.py
index 67bb44a..889f97f 100644
--- a/src/tests/documentation.py
+++ b/src/tests/documentation.py
@@ -1143,10 +1143,12 @@ and not if you pass them as keyword arguments:
```
This can be pretty confusing since non-keyword arguments are passed as
keywork arguments, but it the way it works with ``functools.wraps`` and
-the way many people expect it to work:
+the way many people expect it to work. You can play with
$$chattywrapper
+and see that we are consistent indeed.
+
In the present implementation, decorators generated by ``decorator``
can only be used on user-defined Python functions, methods or coroutines.
I have no interest in decorating generic callable objects. If you want to