Skip to content

Commit 35fdd96

Browse files
made @contextmethod keep original func.__doc__ and improved some doc strings
1 parent da4743a commit 35fdd96

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

robottools/library/context/method.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
"""robottools.context.method
2121
22-
Provides :class:`contextmethod` for creating `testlibrary` method decorators
23-
to separate method implementations for different contexts
24-
of :class:`ContextHandler`s.
22+
Provides :class:`robottools.contextmethod`
23+
for creating Test Library method decorators,
24+
separating method implementations for different contexts
25+
of :class:`robottools.ContextHandler`-derived definitions.
2526
2627
.. moduleauthor:: Stefan Zimmermann <zimmermann.code@gmail.com>
2728
"""
@@ -32,45 +33,46 @@
3233

3334
class contextmethod(object):
3435
"""Class for creating `testlibrary` method decorators
35-
to separate method implementations for different contexts
36-
of :class:`ContextHandler`s.
36+
to separate method implementations for different contexts
37+
of :class:`ContextHandler`s.
3738
38-
- Decorated methods get Context name attributes for decorating
39+
* Decorated methods get Context name attributes for decorating
3940
the Context specific method implementations::
4041
4142
@contextmethod(Handler)
4243
def method(self, ...):
4344
pass
4445
45-
@method.<context name>
46+
@method.context_name
4647
def context_method(self, ...):
4748
...
4849
49-
- By default, on method call only the implementation
50+
* By default, on method call only the implementation
5051
matching the currently active Context will be called.
5152
52-
- A @contextmethod.combined(Handler) decorated method
53+
* A ``@contextmethod.combined(Handler)`` decorated method
5354
will call all context specific implementations
54-
and return a `dict` containing the results by Context name keys.
55-
- contextmethod.combined decorated methods will get an additional
56-
.result decorator for defining a hook method
55+
and return a ``dict`` containing the results by Context name keys.
56+
* contextmethod.combined decorated methods will get an additional
57+
``.result`` decorator for defining a hook method
5758
processing the results dict before final return::
5859
5960
@method.result
6061
def result_method(self, results_dict):
6162
...
6263
return results_dict # or whatever...
6364
64-
- A @contextmethod.combined.lazy(Handler) decorated method
65-
will return a :class:`LazyDict` which will call
66-
the context specific implementations on first ['<context name>'] access.
65+
* A ``@contextmethod.combined.lazy(Handler)`` decorated method
66+
will return a ``moretools.LazyDict`` instance which will call
67+
the context specific implementations on first
68+
``['context_name']`` access.
6769
"""
6870
def __init__(self, *handlers, **options):
6971
"""Create a decorator for the given `handlers`.
7072
71-
- Currently only 1 Handler supported :( - will change soon :)
72-
- `options` are implicitly given
73-
by derived :class:`combined` and :class:`lazy`.
73+
* Currently only 1 Handler supported :( - will change soon :)
74+
* `options` are implicitly given
75+
by derived :class:`contextmethod.combined` and ``moretools.Lazy``.
7476
"""
7577
self.handlers = handlers
7678
self.combined = options.pop('combined', False)
@@ -132,6 +134,7 @@ def resultdeco(resultfunc):
132134
method.result = resultdeco
133135

134136
method.__name__ = func.__name__
137+
method.__doc__ = func.__doc__
135138
return method
136139

137140

0 commit comments

Comments
 (0)