requiresthat 2025.6.16.0__tar.gz → 2025.6.17.1__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.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: requiresthat
3
- Version: 2025.6.16.0
4
- Summary: Decorate an instance method with pre- and/or postconditions that must be fulfilled
3
+ Version: 2025.6.17.1
4
+ Summary: Support for requirements-assisted development
5
5
  Author-email: Ann T Ropea <bedhanger@gmx.de>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://gitlab.com/bedhanger/mwe/-/tree/master/python/requiresthat
@@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "requiresthat"
7
- version = "2025.6.16.0"
7
+ version = "2025.6.17.1"
8
8
  authors = [
9
9
  {name = "Ann T Ropea", email = "bedhanger@gmx.de"},
10
10
  ]
11
- description = "Decorate an instance method with pre- and/or postconditions that must be fulfilled"
11
+ description = "Support for requirements-assisted development"
12
12
  readme = "README.rst"
13
13
  license = "MIT"
14
14
  dependencies = []
@@ -0,0 +1,8 @@
1
+ from ._requires import (
2
+ requires,
3
+ RequirementNotFulfilledError,
4
+ NoCallableConstructError,
5
+ APRIORI,
6
+ POSTMORTEM,
7
+ BEFOREANDAFTER,
8
+ )
@@ -0,0 +1,32 @@
1
+ import textwrap
2
+
3
+ class RequirementNotFulfilledError(Exception):
4
+ """Raise this when a requirement is found wanting"""
5
+
6
+ def __init__(self, that, when, msg=None):
7
+ """Show a default or a user-provided message indicating that some condition is unmet"""
8
+
9
+ self.default_msg = textwrap.dedent(f"""
10
+ {that!r} ({when.name!r}) does not hold
11
+ """).strip()
12
+
13
+ # Call the base class' constructor to init the exception class
14
+ super().__init__(msg or self.default_msg)
15
+
16
+ class NoCallableConstructError(Exception):
17
+ """Raise this when a construct is not callable"""
18
+
19
+ def __init__(self, construct, msg=None):
20
+ """Show a default or a user-provided message"""
21
+
22
+ self.default_msg = textwrap.dedent(f"""
23
+ {construct!r} does not seem to be callable
24
+
25
+ You have managed to place the decorator before a construct that is not callable
26
+ *without* tripping the Python interpreter. Maybe you are a wizard?
27
+
28
+ But, no, we can't carry on like that. Sorry!
29
+ """).strip()
30
+
31
+ # Call the base class' constructor to init the exception class
32
+ super().__init__(msg or self.default_msg)
@@ -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>"""
@@ -18,6 +18,11 @@ def requires(that, when: When = APRIORI) -> Optional[Callable]:
18
18
 
19
19
  The wrapping stops here...
20
20
  """
21
+ try:
22
+ assert callable(func)
23
+ except AssertionError as exc:
24
+ raise NoCallableConstructError(func) from exc
25
+
21
26
  try:
22
27
  if when == APRIORI:
23
28
  assert eval(that)
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: requiresthat
3
- Version: 2025.6.16.0
4
- Summary: Decorate an instance method with pre- and/or postconditions that must be fulfilled
3
+ Version: 2025.6.17.1
4
+ Summary: Support for requirements-assisted development
5
5
  Author-email: Ann T Ropea <bedhanger@gmx.de>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://gitlab.com/bedhanger/mwe/-/tree/master/python/requiresthat
@@ -1 +0,0 @@
1
- from ._requires import requires, RequirementNotFulfilledError, APRIORI, POSTMORTEM, BEFOREANDAFTER
@@ -1,15 +0,0 @@
1
- """Raise this when a requirement is found wanting"""
2
-
3
- import textwrap
4
-
5
- class RequirementNotFulfilledError(Exception):
6
-
7
- def __init__(self, that, when, msg=None):
8
- """Show a default or a user-provided message indicating that some condition is unmet"""
9
-
10
- self.default_msg = textwrap.dedent(f"""
11
- {that!r} ({when.name!r}) does not hold
12
- """).strip()
13
-
14
- # Call the base class' constructor to init the exception class
15
- super().__init__(msg or self.default_msg)