import constable
class Test:
@staticmethod
@constable.trace("a", "b", "c")
def add(a: int, b: int) -> int:
c = a + b
return c
d = Test.add(a=1, b=2)
print(f"{d=}")
/home/mark/wip/feed2fedi/.venv/bin/python /home/mark/.config/JetBrains/PyCharmCE2024.1/scratches/constable_scratch.py
Traceback (most recent call last):
File "/home/mark/.config/JetBrains/PyCharmCE2024.1/scratches/constable_scratch.py", line 11, in <module>
d = Test.add(a=1, b=2)
^^^^^^^^^^^^^^^^^^
File "/home/mark/wip/feed2fedi/.venv/lib/python3.12/site-packages/constable/__init__.py", line 228, in wrapper
ret = executor.execute()
^^^^^^^^^^^^^^^^^^
File "/home/mark/wip/feed2fedi/.venv/lib/python3.12/site-packages/constable/__init__.py", line 190, in execute
result = fn(*self.fn_wrapper.args, **self.fn_wrapper.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mark/wip/feed2fedi/.venv/lib/python3.12/site-packages/constable/__init__.py", line 225, in wrapper
fn_wrapper = FunctionWrapper(func, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mark/wip/feed2fedi/.venv/lib/python3.12/site-packages/constable/__init__.py", line 43, in __init__
self.source_code_lines = inspect.getsource(func).splitlines()
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mark/.rye/py/cpython@3.12.2/install/lib/python3.12/inspect.py", line 1282, in getsource
lines, lnum = getsourcelines(object)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/mark/.rye/py/cpython@3.12.2/install/lib/python3.12/inspect.py", line 1264, in getsourcelines
lines, lnum = findsource(object)
^^^^^^^^^^^^^^^^^^
File "/home/mark/.rye/py/cpython@3.12.2/install/lib/python3.12/inspect.py", line 1093, in findsource
raise OSError('could not get source code')
OSError: could not get source code
Process finished with exit code 1
Started using
constableand loving it so far.I have however noticed that
constableseems to have issues with static methods. The following sample code produces an exception:Following is the traceback when running the above code: