decorator 5.1.1__tar.gz → 5.2.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {decorator-5.1.1 → decorator-5.2.0}/CHANGES.md +17 -1
- {decorator-5.1.1 → decorator-5.2.0}/LICENSE.txt +4 -3
- {decorator-5.1.1 → decorator-5.2.0}/MANIFEST.in +1 -1
- decorator-5.2.0/PKG-INFO +124 -0
- {decorator-5.1.1 → decorator-5.2.0}/README.rst +1 -1
- decorator-5.2.0/pyproject.toml +34 -0
- decorator-5.2.0/src/decorator.egg-info/PKG-INFO +124 -0
- {decorator-5.1.1 → decorator-5.2.0}/src/decorator.egg-info/SOURCES.txt +2 -5
- {decorator-5.1.1 → decorator-5.2.0}/src/decorator.py +9 -5
- {decorator-5.1.1/src → decorator-5.2.0}/tests/test.py +19 -3
- decorator-5.1.1/PKG-INFO +0 -125
- decorator-5.1.1/setup.py +0 -38
- decorator-5.1.1/src/decorator.egg-info/PKG-INFO +0 -125
- decorator-5.1.1/src/decorator.egg-info/not-zip-safe +0 -1
- decorator-5.1.1/src/tests/__init__.py +0 -0
- decorator-5.1.1/src/tests/documentation.py +0 -1890
- {decorator-5.1.1 → decorator-5.2.0}/performance.sh +0 -0
- {decorator-5.1.1 → decorator-5.2.0}/setup.cfg +0 -0
- {decorator-5.1.1 → decorator-5.2.0}/src/decorator.egg-info/dependency_links.txt +0 -0
- {decorator-5.1.1 → decorator-5.2.0}/src/decorator.egg-info/pbr.json +0 -0
- {decorator-5.1.1 → decorator-5.2.0}/src/decorator.egg-info/top_level.txt +0 -0
@@ -3,6 +3,22 @@ HISTORY
|
|
3
3
|
|
4
4
|
## Unreleased
|
5
5
|
|
6
|
+
## 5.2.0 (2025-02-22)
|
7
|
+
|
8
|
+
Changed the build procedure to use pyproject.toml and moved the tests
|
9
|
+
outside of the generated wheel/tarball.
|
10
|
+
|
11
|
+
Added official support for Python 3.11, 3.12, 3.13 (thanks to Hugo van
|
12
|
+
Kemenade).
|
13
|
+
|
14
|
+
Dropped official support for Python < 3.8: the module is
|
15
|
+
expected to work on older Python versions, but I cannot test such
|
16
|
+
versions on GitHub actions, so I cannot claim that it is officially
|
17
|
+
supported.
|
18
|
+
|
19
|
+
Dafu Wu provided support for decorating partial functions, i.e.
|
20
|
+
functions wrapped by functools.partial.
|
21
|
+
|
6
22
|
## 5.1.1 (2022-01-07)
|
7
23
|
|
8
24
|
Sangwoo Shim contributed a fix so that cythonized functions can be decorated.
|
@@ -32,7 +48,7 @@ lacking dunder attributes, like `dict.__setitem__`.
|
|
32
48
|
## 5.0.7 (2021-04-14)
|
33
49
|
|
34
50
|
The decorator module was not passing correctly the defaults inside the
|
35
|
-
`*args` tuple, thanks to Dan Shult for the fix. Also fixed some
|
51
|
+
`*args` tuple, thanks to Dan Shult for the fix. Also fixed some misspellings
|
36
52
|
in the documentation and integrated codespell in the CI, thanks to
|
37
53
|
Christian Clauss.
|
38
54
|
|
@@ -1,13 +1,14 @@
|
|
1
|
-
Copyright (c) 2005-
|
1
|
+
Copyright (c) 2005-2025, Michele Simionato
|
2
2
|
All rights reserved.
|
3
3
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
5
5
|
modification, are permitted provided that the following conditions are
|
6
6
|
met:
|
7
7
|
|
8
|
-
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
9
|
notice, this list of conditions and the following disclaimer.
|
10
|
-
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
12
|
notice, this list of conditions and the following disclaimer in
|
12
13
|
the documentation and/or other materials provided with the
|
13
14
|
distribution.
|
@@ -1,2 +1,2 @@
|
|
1
1
|
include README.rst LICENSE.txt CHANGES.md performance.sh documentation.pdf
|
2
|
-
|
2
|
+
include src/decorator.py
|
decorator-5.2.0/PKG-INFO
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: decorator
|
3
|
+
Version: 5.2.0
|
4
|
+
Summary: Decorators for Humans
|
5
|
+
Author-email: Michele Simionato <michele.simionato@gmail.com>
|
6
|
+
License: BSD-2-Clause
|
7
|
+
Keywords: decorators
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
9
|
+
Classifier: Intended Audience :: Developers
|
10
|
+
Classifier: License :: OSI Approved :: BSD License
|
11
|
+
Classifier: Natural Language :: English
|
12
|
+
Classifier: Operating System :: OS Independent
|
13
|
+
Classifier: Programming Language :: Python
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
22
|
+
Classifier: Topic :: Utilities
|
23
|
+
Requires-Python: >=3.8
|
24
|
+
Description-Content-Type: text/x-rst
|
25
|
+
License-File: LICENSE.txt
|
26
|
+
|
27
|
+
Decorators for Humans
|
28
|
+
=====================
|
29
|
+
|
30
|
+
The goal of the decorator module is to make it easy to define
|
31
|
+
signature-preserving function decorators and decorator factories.
|
32
|
+
It also includes an implementation of multiple dispatch and other niceties
|
33
|
+
(please check the docs). It is released under a two-clauses
|
34
|
+
BSD license, i.e. basically you can do whatever you want with it but I am not
|
35
|
+
responsible.
|
36
|
+
|
37
|
+
Installation
|
38
|
+
-------------
|
39
|
+
|
40
|
+
If you are lazy, just perform
|
41
|
+
|
42
|
+
``$ pip install decorator``
|
43
|
+
|
44
|
+
which will install just the module on your system.
|
45
|
+
|
46
|
+
If you prefer to install the full distribution from source, including
|
47
|
+
the documentation, clone the `GitHub repo`_ or download the tarball_, unpack it and run
|
48
|
+
|
49
|
+
``$ pip install .``
|
50
|
+
|
51
|
+
in the main directory, possibly as superuser.
|
52
|
+
|
53
|
+
.. _tarball: https://pypi.org/project/decorator/#files
|
54
|
+
.. _GitHub repo: https://github.com/micheles/decorator
|
55
|
+
|
56
|
+
Testing
|
57
|
+
--------
|
58
|
+
|
59
|
+
If you have the source code installation you can run the tests with
|
60
|
+
|
61
|
+
`$ python src/tests/test.py -v`
|
62
|
+
|
63
|
+
or (if you have setuptools installed)
|
64
|
+
|
65
|
+
`$ python setup.py test`
|
66
|
+
|
67
|
+
Notice that you may run into trouble if in your system there
|
68
|
+
is an older version of the decorator module; in such a case remove the
|
69
|
+
old version. It is safe even to copy the module `decorator.py` over
|
70
|
+
an existing one, since we kept backward-compatibility for a long time.
|
71
|
+
|
72
|
+
Repository
|
73
|
+
---------------
|
74
|
+
|
75
|
+
The project is hosted on GitHub. You can look at the source here:
|
76
|
+
|
77
|
+
https://github.com/micheles/decorator
|
78
|
+
|
79
|
+
Documentation
|
80
|
+
---------------
|
81
|
+
|
82
|
+
The documentation has been moved to https://github.com/micheles/decorator/blob/master/docs/documentation.md
|
83
|
+
|
84
|
+
From there you can get a PDF version by simply using the print
|
85
|
+
functionality of your browser.
|
86
|
+
|
87
|
+
Here is the documentation for previous versions of the module:
|
88
|
+
|
89
|
+
https://github.com/micheles/decorator/blob/4.3.2/docs/tests.documentation.rst
|
90
|
+
https://github.com/micheles/decorator/blob/4.2.1/docs/tests.documentation.rst
|
91
|
+
https://github.com/micheles/decorator/blob/4.1.2/docs/tests.documentation.rst
|
92
|
+
https://github.com/micheles/decorator/blob/4.0.0/documentation.rst
|
93
|
+
https://github.com/micheles/decorator/blob/3.4.2/documentation.rst
|
94
|
+
|
95
|
+
For the impatient
|
96
|
+
-----------------
|
97
|
+
|
98
|
+
Here is an example of how to define a family of decorators tracing slow
|
99
|
+
operations:
|
100
|
+
|
101
|
+
.. code-block:: python
|
102
|
+
|
103
|
+
from decorator import decorator
|
104
|
+
|
105
|
+
@decorator
|
106
|
+
def warn_slow(func, timelimit=60, *args, **kw):
|
107
|
+
t0 = time.time()
|
108
|
+
result = func(*args, **kw)
|
109
|
+
dt = time.time() - t0
|
110
|
+
if dt > timelimit:
|
111
|
+
logging.warning('%s took %d seconds', func.__name__, dt)
|
112
|
+
else:
|
113
|
+
logging.info('%s took %d seconds', func.__name__, dt)
|
114
|
+
return result
|
115
|
+
|
116
|
+
@warn_slow # warn if it takes more than 1 minute
|
117
|
+
def preprocess_input_files(inputdir, tempdir):
|
118
|
+
...
|
119
|
+
|
120
|
+
@warn_slow(timelimit=600) # warn if it takes more than 10 minutes
|
121
|
+
def run_calculation(tempdir, outdir):
|
122
|
+
...
|
123
|
+
|
124
|
+
Enjoy!
|
@@ -82,7 +82,7 @@ operations:
|
|
82
82
|
result = func(*args, **kw)
|
83
83
|
dt = time.time() - t0
|
84
84
|
if dt > timelimit:
|
85
|
-
logging.
|
85
|
+
logging.warning('%s took %d seconds', func.__name__, dt)
|
86
86
|
else:
|
87
87
|
logging.info('%s took %d seconds', func.__name__, dt)
|
88
88
|
return result
|
@@ -0,0 +1,34 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "decorator"
|
7
|
+
authors = [
|
8
|
+
{name = "Michele Simionato", email = "michele.simionato@gmail.com"},
|
9
|
+
]
|
10
|
+
description = "Decorators for Humans"
|
11
|
+
readme = "README.rst"
|
12
|
+
dynamic = ["version"]
|
13
|
+
requires-python = ">=3.8"
|
14
|
+
keywords = ["decorators"]
|
15
|
+
license = {text = "BSD-2-Clause"}
|
16
|
+
classifiers = [
|
17
|
+
'Development Status :: 5 - Production/Stable',
|
18
|
+
'Intended Audience :: Developers',
|
19
|
+
'License :: OSI Approved :: BSD License',
|
20
|
+
'Natural Language :: English',
|
21
|
+
'Operating System :: OS Independent',
|
22
|
+
'Programming Language :: Python',
|
23
|
+
'Programming Language :: Python :: 3.8',
|
24
|
+
'Programming Language :: Python :: 3.9',
|
25
|
+
'Programming Language :: Python :: 3.10',
|
26
|
+
'Programming Language :: Python :: 3.11',
|
27
|
+
'Programming Language :: Python :: 3.12',
|
28
|
+
'Programming Language :: Python :: 3.13',
|
29
|
+
'Programming Language :: Python :: Implementation :: CPython',
|
30
|
+
'Topic :: Software Development :: Libraries',
|
31
|
+
'Topic :: Utilities']
|
32
|
+
|
33
|
+
[tool.setuptools.dynamic]
|
34
|
+
version.attr = "decorator.__version__"
|
@@ -0,0 +1,124 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: decorator
|
3
|
+
Version: 5.2.0
|
4
|
+
Summary: Decorators for Humans
|
5
|
+
Author-email: Michele Simionato <michele.simionato@gmail.com>
|
6
|
+
License: BSD-2-Clause
|
7
|
+
Keywords: decorators
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
9
|
+
Classifier: Intended Audience :: Developers
|
10
|
+
Classifier: License :: OSI Approved :: BSD License
|
11
|
+
Classifier: Natural Language :: English
|
12
|
+
Classifier: Operating System :: OS Independent
|
13
|
+
Classifier: Programming Language :: Python
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
22
|
+
Classifier: Topic :: Utilities
|
23
|
+
Requires-Python: >=3.8
|
24
|
+
Description-Content-Type: text/x-rst
|
25
|
+
License-File: LICENSE.txt
|
26
|
+
|
27
|
+
Decorators for Humans
|
28
|
+
=====================
|
29
|
+
|
30
|
+
The goal of the decorator module is to make it easy to define
|
31
|
+
signature-preserving function decorators and decorator factories.
|
32
|
+
It also includes an implementation of multiple dispatch and other niceties
|
33
|
+
(please check the docs). It is released under a two-clauses
|
34
|
+
BSD license, i.e. basically you can do whatever you want with it but I am not
|
35
|
+
responsible.
|
36
|
+
|
37
|
+
Installation
|
38
|
+
-------------
|
39
|
+
|
40
|
+
If you are lazy, just perform
|
41
|
+
|
42
|
+
``$ pip install decorator``
|
43
|
+
|
44
|
+
which will install just the module on your system.
|
45
|
+
|
46
|
+
If you prefer to install the full distribution from source, including
|
47
|
+
the documentation, clone the `GitHub repo`_ or download the tarball_, unpack it and run
|
48
|
+
|
49
|
+
``$ pip install .``
|
50
|
+
|
51
|
+
in the main directory, possibly as superuser.
|
52
|
+
|
53
|
+
.. _tarball: https://pypi.org/project/decorator/#files
|
54
|
+
.. _GitHub repo: https://github.com/micheles/decorator
|
55
|
+
|
56
|
+
Testing
|
57
|
+
--------
|
58
|
+
|
59
|
+
If you have the source code installation you can run the tests with
|
60
|
+
|
61
|
+
`$ python src/tests/test.py -v`
|
62
|
+
|
63
|
+
or (if you have setuptools installed)
|
64
|
+
|
65
|
+
`$ python setup.py test`
|
66
|
+
|
67
|
+
Notice that you may run into trouble if in your system there
|
68
|
+
is an older version of the decorator module; in such a case remove the
|
69
|
+
old version. It is safe even to copy the module `decorator.py` over
|
70
|
+
an existing one, since we kept backward-compatibility for a long time.
|
71
|
+
|
72
|
+
Repository
|
73
|
+
---------------
|
74
|
+
|
75
|
+
The project is hosted on GitHub. You can look at the source here:
|
76
|
+
|
77
|
+
https://github.com/micheles/decorator
|
78
|
+
|
79
|
+
Documentation
|
80
|
+
---------------
|
81
|
+
|
82
|
+
The documentation has been moved to https://github.com/micheles/decorator/blob/master/docs/documentation.md
|
83
|
+
|
84
|
+
From there you can get a PDF version by simply using the print
|
85
|
+
functionality of your browser.
|
86
|
+
|
87
|
+
Here is the documentation for previous versions of the module:
|
88
|
+
|
89
|
+
https://github.com/micheles/decorator/blob/4.3.2/docs/tests.documentation.rst
|
90
|
+
https://github.com/micheles/decorator/blob/4.2.1/docs/tests.documentation.rst
|
91
|
+
https://github.com/micheles/decorator/blob/4.1.2/docs/tests.documentation.rst
|
92
|
+
https://github.com/micheles/decorator/blob/4.0.0/documentation.rst
|
93
|
+
https://github.com/micheles/decorator/blob/3.4.2/documentation.rst
|
94
|
+
|
95
|
+
For the impatient
|
96
|
+
-----------------
|
97
|
+
|
98
|
+
Here is an example of how to define a family of decorators tracing slow
|
99
|
+
operations:
|
100
|
+
|
101
|
+
.. code-block:: python
|
102
|
+
|
103
|
+
from decorator import decorator
|
104
|
+
|
105
|
+
@decorator
|
106
|
+
def warn_slow(func, timelimit=60, *args, **kw):
|
107
|
+
t0 = time.time()
|
108
|
+
result = func(*args, **kw)
|
109
|
+
dt = time.time() - t0
|
110
|
+
if dt > timelimit:
|
111
|
+
logging.warning('%s took %d seconds', func.__name__, dt)
|
112
|
+
else:
|
113
|
+
logging.info('%s took %d seconds', func.__name__, dt)
|
114
|
+
return result
|
115
|
+
|
116
|
+
@warn_slow # warn if it takes more than 1 minute
|
117
|
+
def preprocess_input_files(inputdir, tempdir):
|
118
|
+
...
|
119
|
+
|
120
|
+
@warn_slow(timelimit=600) # warn if it takes more than 10 minutes
|
121
|
+
def run_calculation(tempdir, outdir):
|
122
|
+
...
|
123
|
+
|
124
|
+
Enjoy!
|
@@ -3,15 +3,12 @@ LICENSE.txt
|
|
3
3
|
MANIFEST.in
|
4
4
|
README.rst
|
5
5
|
performance.sh
|
6
|
+
pyproject.toml
|
6
7
|
setup.cfg
|
7
|
-
setup.py
|
8
8
|
src/decorator.py
|
9
9
|
src/decorator.egg-info/PKG-INFO
|
10
10
|
src/decorator.egg-info/SOURCES.txt
|
11
11
|
src/decorator.egg-info/dependency_links.txt
|
12
|
-
src/decorator.egg-info/not-zip-safe
|
13
12
|
src/decorator.egg-info/pbr.json
|
14
13
|
src/decorator.egg-info/top_level.txt
|
15
|
-
|
16
|
-
src/tests/documentation.py
|
17
|
-
src/tests/test.py
|
14
|
+
tests/test.py
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# ######################### LICENSE ############################ #
|
2
2
|
|
3
|
-
# Copyright (c) 2005-
|
3
|
+
# Copyright (c) 2005-2025, Michele Simionato
|
4
4
|
# All rights reserved.
|
5
5
|
|
6
6
|
# Redistribution and use in source and binary forms, with or without
|
@@ -37,10 +37,11 @@ import sys
|
|
37
37
|
import inspect
|
38
38
|
import operator
|
39
39
|
import itertools
|
40
|
+
import functools
|
40
41
|
from contextlib import _GeneratorContextManager
|
41
42
|
from inspect import getfullargspec, iscoroutinefunction, isgeneratorfunction
|
42
43
|
|
43
|
-
__version__ = '5.
|
44
|
+
__version__ = '5.2.0'
|
44
45
|
|
45
46
|
DEF = re.compile(r'\s*def\s*([_\w][_\w\d]*)\s*\(')
|
46
47
|
POS = inspect.Parameter.POSITIONAL_OR_KEYWORD
|
@@ -71,7 +72,7 @@ class FunctionMaker(object):
|
|
71
72
|
self.name = '_lambda_'
|
72
73
|
self.doc = func.__doc__
|
73
74
|
self.module = func.__module__
|
74
|
-
if inspect.isroutine(func):
|
75
|
+
if inspect.isroutine(func) or isinstance(func, functools.partial):
|
75
76
|
argspec = getfullargspec(func)
|
76
77
|
self.annotations = getattr(func, '__annotations__', {})
|
77
78
|
for a in ('args', 'varargs', 'varkw', 'defaults', 'kwonlyargs',
|
@@ -214,6 +215,8 @@ def decorate(func, caller, extras=(), kwsyntax=False):
|
|
214
215
|
does. By default kwsyntax is False and the the arguments are untouched.
|
215
216
|
"""
|
216
217
|
sig = inspect.signature(func)
|
218
|
+
if isinstance(func, functools.partial):
|
219
|
+
func = functools.update_wrapper(func, func.func)
|
217
220
|
if iscoroutinefunction(caller):
|
218
221
|
async def fun(*args, **kw):
|
219
222
|
if not kwsyntax:
|
@@ -230,6 +233,7 @@ def decorate(func, caller, extras=(), kwsyntax=False):
|
|
230
233
|
if not kwsyntax:
|
231
234
|
args, kw = fix(args, kw, sig)
|
232
235
|
return caller(func, *(extras + args), **kw)
|
236
|
+
|
233
237
|
fun.__name__ = func.__name__
|
234
238
|
fun.__doc__ = func.__doc__
|
235
239
|
fun.__wrapped__ = func
|
@@ -419,8 +423,8 @@ def dispatch_on(*dispatch_args):
|
|
419
423
|
"""
|
420
424
|
check(types)
|
421
425
|
lst = []
|
422
|
-
for
|
423
|
-
lst.append(tuple(a.__name__ for a in
|
426
|
+
for ancs in itertools.product(*ancestors(*types)):
|
427
|
+
lst.append(tuple(a.__name__ for a in ancs))
|
424
428
|
return lst
|
425
429
|
|
426
430
|
def _dispatch(dispatch_args, *args, **kw):
|
@@ -3,7 +3,8 @@ import doctest
|
|
3
3
|
import unittest
|
4
4
|
import decimal
|
5
5
|
import inspect
|
6
|
-
|
6
|
+
import functools
|
7
|
+
import asyncio
|
7
8
|
from collections import defaultdict, ChainMap, abc as c
|
8
9
|
from decorator import dispatch_on, contextmanager, decorator
|
9
10
|
try:
|
@@ -30,7 +31,7 @@ async def before_after(coro, *args, **kwargs):
|
|
30
31
|
|
31
32
|
@decorator
|
32
33
|
def coro_to_func(coro, *args, **kw):
|
33
|
-
return
|
34
|
+
return asyncio.run(coro(*args, **kw))
|
34
35
|
|
35
36
|
|
36
37
|
class CoroutineTestCase(unittest.TestCase):
|
@@ -39,7 +40,7 @@ class CoroutineTestCase(unittest.TestCase):
|
|
39
40
|
async def coro(x):
|
40
41
|
return x
|
41
42
|
self.assertTrue(inspect.iscoroutinefunction(coro))
|
42
|
-
out =
|
43
|
+
out = asyncio.run(coro('x'))
|
43
44
|
self.assertEqual(out, '<before>x<after>')
|
44
45
|
|
45
46
|
def test_coro_to_func(self):
|
@@ -509,5 +510,20 @@ class TestSingleDispatch(unittest.TestCase):
|
|
509
510
|
h(u)
|
510
511
|
|
511
512
|
|
513
|
+
@decorator
|
514
|
+
def partial_before_after(func, *args, **kwargs):
|
515
|
+
return "<before>" + func(*args, **kwargs) + "<after>"
|
516
|
+
|
517
|
+
|
518
|
+
class PartialTestCase(unittest.TestCase):
|
519
|
+
def test_before_after(self):
|
520
|
+
def origin_func(x, y):
|
521
|
+
return x + y
|
522
|
+
_func = functools.partial(origin_func, "x")
|
523
|
+
partial_func = partial_before_after(_func)
|
524
|
+
out = partial_func("y")
|
525
|
+
self.assertEqual(out, '<before>xy<after>')
|
526
|
+
|
527
|
+
|
512
528
|
if __name__ == '__main__':
|
513
529
|
unittest.main()
|
decorator-5.1.1/PKG-INFO
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
Metadata-Version: 1.2
|
2
|
-
Name: decorator
|
3
|
-
Version: 5.1.1
|
4
|
-
Summary: Decorators for Humans
|
5
|
-
Home-page: https://github.com/micheles/decorator
|
6
|
-
Author: Michele Simionato
|
7
|
-
Author-email: michele.simionato@gmail.com
|
8
|
-
License: new BSD License
|
9
|
-
Description: Decorators for Humans
|
10
|
-
=====================
|
11
|
-
|
12
|
-
The goal of the decorator module is to make it easy to define
|
13
|
-
signature-preserving function decorators and decorator factories.
|
14
|
-
It also includes an implementation of multiple dispatch and other niceties
|
15
|
-
(please check the docs). It is released under a two-clauses
|
16
|
-
BSD license, i.e. basically you can do whatever you want with it but I am not
|
17
|
-
responsible.
|
18
|
-
|
19
|
-
Installation
|
20
|
-
-------------
|
21
|
-
|
22
|
-
If you are lazy, just perform
|
23
|
-
|
24
|
-
``$ pip install decorator``
|
25
|
-
|
26
|
-
which will install just the module on your system.
|
27
|
-
|
28
|
-
If you prefer to install the full distribution from source, including
|
29
|
-
the documentation, clone the `GitHub repo`_ or download the tarball_, unpack it and run
|
30
|
-
|
31
|
-
``$ pip install .``
|
32
|
-
|
33
|
-
in the main directory, possibly as superuser.
|
34
|
-
|
35
|
-
.. _tarball: https://pypi.org/project/decorator/#files
|
36
|
-
.. _GitHub repo: https://github.com/micheles/decorator
|
37
|
-
|
38
|
-
Testing
|
39
|
-
--------
|
40
|
-
|
41
|
-
If you have the source code installation you can run the tests with
|
42
|
-
|
43
|
-
`$ python src/tests/test.py -v`
|
44
|
-
|
45
|
-
or (if you have setuptools installed)
|
46
|
-
|
47
|
-
`$ python setup.py test`
|
48
|
-
|
49
|
-
Notice that you may run into trouble if in your system there
|
50
|
-
is an older version of the decorator module; in such a case remove the
|
51
|
-
old version. It is safe even to copy the module `decorator.py` over
|
52
|
-
an existing one, since we kept backward-compatibility for a long time.
|
53
|
-
|
54
|
-
Repository
|
55
|
-
---------------
|
56
|
-
|
57
|
-
The project is hosted on GitHub. You can look at the source here:
|
58
|
-
|
59
|
-
https://github.com/micheles/decorator
|
60
|
-
|
61
|
-
Documentation
|
62
|
-
---------------
|
63
|
-
|
64
|
-
The documentation has been moved to https://github.com/micheles/decorator/blob/master/docs/documentation.md
|
65
|
-
|
66
|
-
From there you can get a PDF version by simply using the print
|
67
|
-
functionality of your browser.
|
68
|
-
|
69
|
-
Here is the documentation for previous versions of the module:
|
70
|
-
|
71
|
-
https://github.com/micheles/decorator/blob/4.3.2/docs/tests.documentation.rst
|
72
|
-
https://github.com/micheles/decorator/blob/4.2.1/docs/tests.documentation.rst
|
73
|
-
https://github.com/micheles/decorator/blob/4.1.2/docs/tests.documentation.rst
|
74
|
-
https://github.com/micheles/decorator/blob/4.0.0/documentation.rst
|
75
|
-
https://github.com/micheles/decorator/blob/3.4.2/documentation.rst
|
76
|
-
|
77
|
-
For the impatient
|
78
|
-
-----------------
|
79
|
-
|
80
|
-
Here is an example of how to define a family of decorators tracing slow
|
81
|
-
operations:
|
82
|
-
|
83
|
-
.. code-block:: python
|
84
|
-
|
85
|
-
from decorator import decorator
|
86
|
-
|
87
|
-
@decorator
|
88
|
-
def warn_slow(func, timelimit=60, *args, **kw):
|
89
|
-
t0 = time.time()
|
90
|
-
result = func(*args, **kw)
|
91
|
-
dt = time.time() - t0
|
92
|
-
if dt > timelimit:
|
93
|
-
logging.warn('%s took %d seconds', func.__name__, dt)
|
94
|
-
else:
|
95
|
-
logging.info('%s took %d seconds', func.__name__, dt)
|
96
|
-
return result
|
97
|
-
|
98
|
-
@warn_slow # warn if it takes more than 1 minute
|
99
|
-
def preprocess_input_files(inputdir, tempdir):
|
100
|
-
...
|
101
|
-
|
102
|
-
@warn_slow(timelimit=600) # warn if it takes more than 10 minutes
|
103
|
-
def run_calculation(tempdir, outdir):
|
104
|
-
...
|
105
|
-
|
106
|
-
Enjoy!
|
107
|
-
|
108
|
-
Keywords: decorators generic utility
|
109
|
-
Platform: All
|
110
|
-
Classifier: Development Status :: 5 - Production/Stable
|
111
|
-
Classifier: Intended Audience :: Developers
|
112
|
-
Classifier: License :: OSI Approved :: BSD License
|
113
|
-
Classifier: Natural Language :: English
|
114
|
-
Classifier: Operating System :: OS Independent
|
115
|
-
Classifier: Programming Language :: Python
|
116
|
-
Classifier: Programming Language :: Python :: 3.5
|
117
|
-
Classifier: Programming Language :: Python :: 3.6
|
118
|
-
Classifier: Programming Language :: Python :: 3.7
|
119
|
-
Classifier: Programming Language :: Python :: 3.8
|
120
|
-
Classifier: Programming Language :: Python :: 3.9
|
121
|
-
Classifier: Programming Language :: Python :: 3.10
|
122
|
-
Classifier: Programming Language :: Python :: Implementation :: CPython
|
123
|
-
Classifier: Topic :: Software Development :: Libraries
|
124
|
-
Classifier: Topic :: Utilities
|
125
|
-
Requires-Python: >=3.5
|
decorator-5.1.1/setup.py
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
from setuptools import setup
|
2
|
-
|
3
|
-
dic = dict(__file__=None)
|
4
|
-
exec(open('src/decorator.py').read(), dic) # extract the __version__
|
5
|
-
VERSION = dic['__version__']
|
6
|
-
|
7
|
-
|
8
|
-
if __name__ == '__main__':
|
9
|
-
setup(name='decorator',
|
10
|
-
version=VERSION,
|
11
|
-
description='Decorators for Humans',
|
12
|
-
long_description=open('README.rst').read(),
|
13
|
-
author='Michele Simionato',
|
14
|
-
author_email='michele.simionato@gmail.com',
|
15
|
-
url='https://github.com/micheles/decorator',
|
16
|
-
license="new BSD License",
|
17
|
-
package_dir={'': 'src'},
|
18
|
-
py_modules=['decorator'],
|
19
|
-
keywords="decorators generic utility",
|
20
|
-
platforms=["All"],
|
21
|
-
python_requires='>=3.5',
|
22
|
-
classifiers=['Development Status :: 5 - Production/Stable',
|
23
|
-
'Intended Audience :: Developers',
|
24
|
-
'License :: OSI Approved :: BSD License',
|
25
|
-
'Natural Language :: English',
|
26
|
-
'Operating System :: OS Independent',
|
27
|
-
'Programming Language :: Python',
|
28
|
-
'Programming Language :: Python :: 3.5',
|
29
|
-
'Programming Language :: Python :: 3.6',
|
30
|
-
'Programming Language :: Python :: 3.7',
|
31
|
-
'Programming Language :: Python :: 3.8',
|
32
|
-
'Programming Language :: Python :: 3.9',
|
33
|
-
'Programming Language :: Python :: 3.10',
|
34
|
-
'Programming Language :: Python :: Implementation :: CPython',
|
35
|
-
'Topic :: Software Development :: Libraries',
|
36
|
-
'Topic :: Utilities'],
|
37
|
-
test_suite='tests',
|
38
|
-
zip_safe=False)
|