Giter Site home page Giter Site logo

saurabh0719 / constable Goto Github PK

View Code? Open in Web Editor NEW
90.0 90.0 1.0 69 KB

Constable lets you be lazy by inserting prints directly into your AST for stateful debugging :man_juggling:

Home Page: https://pypi.org/project/constable

License: MIT License

Python 100.00%
debug debugging-tool decorators python

constable's Issues

Exception with static method

Started using constable and loving it so far.

I have however noticed that constable seems to have issues with static methods. The following sample code produces an exception:

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=}")

Following is the traceback when running the above code:

/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/[email protected]/install/lib/python3.12/inspect.py", line 1282, in getsource
    lines, lnum = getsourcelines(object)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mark/.rye/py/[email protected]/install/lib/python3.12/inspect.py", line 1264, in getsourcelines
    lines, lnum = findsource(object)
                  ^^^^^^^^^^^^^^^^^^
  File "/home/mark/.rye/py/[email protected]/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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.