requiresthat 2025.6.17.0__py3-none-any.whl → 2025.6.18.1__py3-none-any.whl
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.
- requiresthat/__init__.py +8 -1
- requiresthat/_exceptions.py +23 -4
- requiresthat/_requires.py +31 -10
- {requiresthat-2025.6.17.0.dist-info → requiresthat-2025.6.18.1.dist-info}/METADATA +1 -1
- requiresthat-2025.6.18.1.dist-info/RECORD +8 -0
- requiresthat-2025.6.17.0.dist-info/RECORD +0 -8
- {requiresthat-2025.6.17.0.dist-info → requiresthat-2025.6.18.1.dist-info}/WHEEL +0 -0
- {requiresthat-2025.6.17.0.dist-info → requiresthat-2025.6.18.1.dist-info}/top_level.txt +0 -0
requiresthat/__init__.py
CHANGED
requiresthat/_exceptions.py
CHANGED
@@ -1,14 +1,33 @@
|
|
1
|
-
"""Raise this when a requirement is found wanting"""
|
2
|
-
|
3
1
|
import textwrap
|
4
2
|
|
5
3
|
class RequirementNotFulfilledError(Exception):
|
4
|
+
"""Raise this when a requirement is found wanting"""
|
6
5
|
|
7
|
-
def __init__(self, that, when, msg=None):
|
6
|
+
def __init__(self, that, when, subwhen=str(), msg=None):
|
8
7
|
"""Show a default or a user-provided message indicating that some condition is unmet"""
|
9
8
|
|
9
|
+
if subwhen:
|
10
|
+
subwhen = f' ({subwhen.name!r})'
|
10
11
|
self.default_msg = textwrap.dedent(f"""
|
11
|
-
{that!r} ({when.name!r}) does not hold
|
12
|
+
{that!r} ({when.name!r}{subwhen}) does not hold
|
13
|
+
""").strip()
|
14
|
+
|
15
|
+
# Call the base class' constructor to init the exception class
|
16
|
+
super().__init__(msg or self.default_msg)
|
17
|
+
|
18
|
+
class NoCallableConstructError(Exception):
|
19
|
+
"""Raise this when a construct is not callable"""
|
20
|
+
|
21
|
+
def __init__(self, construct, msg=None):
|
22
|
+
"""Show a default or a user-provided message"""
|
23
|
+
|
24
|
+
self.default_msg = textwrap.dedent(f"""
|
25
|
+
{construct!r} does not seem to be callable
|
26
|
+
|
27
|
+
You have managed to place the decorator before a construct that is not callable
|
28
|
+
*without* tripping the Python interpreter. Maybe you are a wizard?
|
29
|
+
|
30
|
+
But, no, we can't carry on like that. Sorry!
|
12
31
|
""").strip()
|
13
32
|
|
14
33
|
# Call the base class' constructor to init the exception class
|
requiresthat/_requires.py
CHANGED
@@ -4,7 +4,7 @@ from typing import Optional, Callable
|
|
4
4
|
from functools import wraps
|
5
5
|
|
6
6
|
from ._when import When, APRIORI, POSTMORTEM, BEFOREANDAFTER
|
7
|
-
from ._exceptions import RequirementNotFulfilledError
|
7
|
+
from ._exceptions import RequirementNotFulfilledError, NoCallableConstructError
|
8
8
|
|
9
9
|
def requires(that, when: When = APRIORI) -> Optional[Callable]:
|
10
10
|
"""Require <that> of the decoratee, and require it <when>"""
|
@@ -19,22 +19,43 @@ def requires(that, when: When = APRIORI) -> Optional[Callable]:
|
|
19
19
|
The wrapping stops here...
|
20
20
|
"""
|
21
21
|
try:
|
22
|
+
assert callable(func)
|
23
|
+
except AssertionError as exc:
|
24
|
+
raise NoCallableConstructError(func) from exc
|
25
|
+
else:
|
26
|
+
# Since we want to give detailed sub-failure diax in case of BEFOREANDAFTER,
|
27
|
+
# economisng on the ifs below is tricky.
|
22
28
|
if when == APRIORI:
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
try:
|
30
|
+
assert eval(that)
|
31
|
+
except AssertionError as exc:
|
32
|
+
raise RequirementNotFulfilledError(that, when) from exc
|
33
|
+
else:
|
34
|
+
func(self, *pargs, **kwargs)
|
35
|
+
|
26
36
|
elif when == POSTMORTEM:
|
27
37
|
func(self, *pargs, **kwargs)
|
28
|
-
|
38
|
+
try:
|
39
|
+
assert eval(that)
|
40
|
+
except AssertionError as exc:
|
41
|
+
raise RequirementNotFulfilledError(that, when) from exc
|
42
|
+
|
29
43
|
elif when == BEFOREANDAFTER:
|
30
|
-
|
31
|
-
|
32
|
-
|
44
|
+
try:
|
45
|
+
assert eval(that)
|
46
|
+
except AssertionError as exc:
|
47
|
+
raise RequirementNotFulfilledError(that, when, APRIORI) from exc
|
48
|
+
else:
|
49
|
+
func(self, *pargs, **kwargs)
|
50
|
+
try:
|
51
|
+
assert eval(that)
|
52
|
+
except AssertionError as exc:
|
53
|
+
raise RequirementNotFulfilledError(that, when, POSTMORTEM) from exc
|
54
|
+
|
33
55
|
# We don't need an else clause; trying to enlist something that's not in the enum
|
34
56
|
# will be penalised with an AttributeError, and small typos will be healed with a
|
35
57
|
# suggestion as to what you might have meant.
|
36
|
-
|
37
|
-
raise RequirementNotFulfilledError(that, when) from exc
|
58
|
+
|
38
59
|
return inner_wrapper
|
39
60
|
|
40
61
|
return func_wrapper
|
@@ -0,0 +1,8 @@
|
|
1
|
+
requiresthat/__init__.py,sha256=VTyJru4K2_e7UEa0od6kXU7M8ovfD176GXEXqtNf-nY,154
|
2
|
+
requiresthat/_exceptions.py,sha256=-Q9lhvHnSapP_UGMAnlXxwDaGcxagULIe5oP5h8a2IU,1275
|
3
|
+
requiresthat/_requires.py,sha256=5hQMT5T5VZuQj6W13108j_cedx4wKzJ7Kt4xseOR4cI,2447
|
4
|
+
requiresthat/_when.py,sha256=VoGuvoG9WDEMIPeKnxAsjMTaCMhgSszf4xxa1vLn5aU,299
|
5
|
+
requiresthat-2025.6.18.1.dist-info/METADATA,sha256=anVc8oEKzMwwStJ7PH7tCHDLFBaQ0qTNteQd3-ZbJ5s,1575
|
6
|
+
requiresthat-2025.6.18.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
requiresthat-2025.6.18.1.dist-info/top_level.txt,sha256=mUgMTpAG75GYtt5_rVajUyWp-O_1VrrkqRo_hY9L9So,13
|
8
|
+
requiresthat-2025.6.18.1.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
requiresthat/__init__.py,sha256=-pvz61UhmWhwzjbKTHQ83_YqZx1MXQEvqSgb7Q0d9jE,99
|
2
|
-
requiresthat/_exceptions.py,sha256=bgrTgn3JCJv_KbYIpaghZ8v-SP5fiOpzeFC5zB8uq8M,504
|
3
|
-
requiresthat/_requires.py,sha256=F28tp_3L_E06ERsSGkPx-YrbBolmGO1NymJZINtocts,1562
|
4
|
-
requiresthat/_when.py,sha256=VoGuvoG9WDEMIPeKnxAsjMTaCMhgSszf4xxa1vLn5aU,299
|
5
|
-
requiresthat-2025.6.17.0.dist-info/METADATA,sha256=w3FELaW74-gCOcfxFo9DaiTkLGGJ1LlA17Ka_2itPYM,1575
|
6
|
-
requiresthat-2025.6.17.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
-
requiresthat-2025.6.17.0.dist-info/top_level.txt,sha256=mUgMTpAG75GYtt5_rVajUyWp-O_1VrrkqRo_hY9L9So,13
|
8
|
-
requiresthat-2025.6.17.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|