diff options
| author | Michele Simionato <michele.simionato@gmail.com> | 2011-01-01 09:21:48 +0100 |
|---|---|---|
| committer | Michele Simionato <michele.simionato@gmail.com> | 2011-01-01 09:21:48 +0100 |
| commit | 8ad682164653a2653db6e0df831b71261d174367 (patch) | |
| tree | 8bff128d618cd18fc650bfccac87e6e61ce6a9d5 /documentation3.py | |
| parent | ef9e13545a960aecf62d529da7d74cd2d39ec579 (diff) | |
| download | python-decorator-git-8ad682164653a2653db6e0df831b71261d174367.tar.gz | |
Changed the syntax coloring
Diffstat (limited to 'documentation3.py')
| -rw-r--r-- | documentation3.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/documentation3.py b/documentation3.py index c34842e..3df2e47 100644 --- a/documentation3.py +++ b/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 |
