summaryrefslogtreecommitdiff
path: root/decorator/documentation3.py
diff options
context:
space:
mode:
Diffstat (limited to 'decorator/documentation3.py')
-rw-r--r--decorator/documentation3.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/decorator/documentation3.py b/decorator/documentation3.py
index c34842e..3df2e47 100644
--- a/decorator/documentation3.py
+++ b/decorator/documentation3.py
@@ -244,6 +244,8 @@ stored in a dictionary named ``__annotations__``. The decorator module,
starting from release 3.3, is able to understand and to preserve the
annotations. Here is an example:
+.. code-block:: python
+
>>> @trace
... def f(x: 'the first argument', y: 'default argument'=1, z=2,
... *args: 'varargs', **kw: 'kwargs'):
@@ -252,6 +254,8 @@ annotations. Here is an example:
In order to introspect functions with annotations, one needs the
utility ``inspect.getfullargspec``, new in Python 3:
+.. code-block:: python
+
>>> from inspect import getfullargspec
>>> argspec = getfullargspec(f)
>>> argspec.args
@@ -270,11 +274,15 @@ utility ``inspect.getfullargspec``, new in Python 3:
You can also check that the ``__annotations__`` dictionary is preserved:
+.. code-block:: python
+
>>> f.__annotations__ == f.undecorated.__annotations__
True
The two dictionaries are different objects, though
+.. code-block:: python
+
>>> id(f.__annotations__) != id(f.undecorated.__annotations__)
True