pyessential 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyessential-0.1.2/pyessential.egg-info → pyessential-0.1.3}/PKG-INFO +1 -1
- pyessential-0.1.3/pyessential/_version.py +1 -0
- pyessential-0.1.3/pyessential/decorators/__init__.py +7 -0
- pyessential-0.1.3/pyessential/decorators/deprecated.py +42 -0
- {pyessential-0.1.2 → pyessential-0.1.3/pyessential.egg-info}/PKG-INFO +1 -1
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential.egg-info/SOURCES.txt +4 -2
- pyessential-0.1.3/tests/decorators/test_deprecated.py +41 -0
- pyessential-0.1.2/pyessential/_version.py +0 -1
- pyessential-0.1.2/pyessential/decorators/__init__.py +0 -3
- {pyessential-0.1.2 → pyessential-0.1.3}/LICENSE +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/MANIFEST.in +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/README.md +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential/__init__.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential/__main__.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential/cli.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential/decorators/timer.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential/generators.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential/logger.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential.egg-info/dependency_links.txt +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential.egg-info/entry_points.txt +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyessential.egg-info/top_level.txt +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/pyproject.toml +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/setup.cfg +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/setup.py +0 -0
- /pyessential-0.1.2/tests/test_decorators.py → /pyessential-0.1.3/tests/decorators/test_timer.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/tests/test_cli.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/tests/test_generators.py +0 -0
- {pyessential-0.1.2 → pyessential-0.1.3}/tests/test_logger.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.3"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import inspect
|
|
3
|
+
import warnings
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def deprecated(reason="", *, version=None, category=DeprecationWarning):
|
|
7
|
+
"""Mark a function or class as deprecated.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
reason: Message shown to the caller, e.g. "use new_func instead".
|
|
11
|
+
version: Optional version in which it was deprecated.
|
|
12
|
+
category: Warning class to emit (default: DeprecationWarning).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def decorator(obj):
|
|
16
|
+
kind = "class" if inspect.isclass(obj) else "function"
|
|
17
|
+
message = f"{kind} '{obj.__qualname__}' is deprecated"
|
|
18
|
+
if version:
|
|
19
|
+
message += f" since version {version}"
|
|
20
|
+
message += "."
|
|
21
|
+
if reason:
|
|
22
|
+
message += f" {reason}"
|
|
23
|
+
|
|
24
|
+
if inspect.isclass(obj):
|
|
25
|
+
original_init = obj.__init__
|
|
26
|
+
|
|
27
|
+
@functools.wraps(original_init)
|
|
28
|
+
def new_init(self, *args, **kwargs):
|
|
29
|
+
warnings.warn(message, category, stacklevel=2)
|
|
30
|
+
original_init(self, *args, **kwargs)
|
|
31
|
+
|
|
32
|
+
obj.__init__ = new_init
|
|
33
|
+
return obj
|
|
34
|
+
|
|
35
|
+
@functools.wraps(obj)
|
|
36
|
+
def wrapper(*args, **kwargs):
|
|
37
|
+
warnings.warn(message, category, stacklevel=2)
|
|
38
|
+
return obj(*args, **kwargs)
|
|
39
|
+
|
|
40
|
+
return wrapper
|
|
41
|
+
|
|
42
|
+
return decorator
|
|
@@ -16,8 +16,10 @@ pyessential.egg-info/dependency_links.txt
|
|
|
16
16
|
pyessential.egg-info/entry_points.txt
|
|
17
17
|
pyessential.egg-info/top_level.txt
|
|
18
18
|
pyessential/decorators/__init__.py
|
|
19
|
+
pyessential/decorators/deprecated.py
|
|
19
20
|
pyessential/decorators/timer.py
|
|
20
21
|
tests/test_cli.py
|
|
21
|
-
tests/test_decorators.py
|
|
22
22
|
tests/test_generators.py
|
|
23
|
-
tests/test_logger.py
|
|
23
|
+
tests/test_logger.py
|
|
24
|
+
tests/decorators/test_deprecated.py
|
|
25
|
+
tests/decorators/test_timer.py
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pyessential.decorators import deprecated
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_function_warns_and_still_works():
|
|
7
|
+
@deprecated("use new_func instead", version="0.2.0")
|
|
8
|
+
def old(x):
|
|
9
|
+
return x * 2
|
|
10
|
+
|
|
11
|
+
with pytest.warns(DeprecationWarning, match="use new_func instead"):
|
|
12
|
+
assert old(3) == 6
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_preserves_metadata():
|
|
16
|
+
@deprecated("nope")
|
|
17
|
+
def old():
|
|
18
|
+
"""Docstring."""
|
|
19
|
+
|
|
20
|
+
assert old.__name__ == "old"
|
|
21
|
+
assert old.__doc__ == "Docstring."
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_class_warns_on_instantiation():
|
|
25
|
+
@deprecated("use NewClient instead")
|
|
26
|
+
class Old:
|
|
27
|
+
def __init__(self, value):
|
|
28
|
+
self.value = value
|
|
29
|
+
|
|
30
|
+
with pytest.warns(DeprecationWarning, match="NewClient"):
|
|
31
|
+
obj = Old(5)
|
|
32
|
+
assert obj.value == 5
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_custom_category():
|
|
36
|
+
@deprecated("gone soon", category=FutureWarning)
|
|
37
|
+
def old():
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
with pytest.warns(FutureWarning):
|
|
41
|
+
old()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/pyessential-0.1.2/tests/test_decorators.py → /pyessential-0.1.3/tests/decorators/test_timer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|