Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with ipdb #111

Open
riyadparvez opened this issue Oct 8, 2024 · 3 comments
Open

Crash with ipdb #111

riyadparvez opened this issue Oct 8, 2024 · 3 comments

Comments

@riyadparvez
Copy link

from objprint import config, op, install

install()
config(
    line_number=True,
    arg_name=True,
)

for i in range(3):
    op(i)
    import ipdb; ipdb.set_trace()

On first hit of the breaskpoint if I continue and on the second hit of the op(i) throws exception.

The traceback:

Traceback (most recent call last):
  File "/Users/-----------/test.py", line 10, in <module>
    op(i)
  File "/opt/homebrew/lib/python3.11/site-packages/objprint/objprint.py", line 95, in __call__
    args = self.frame_analyzer.get_args(call_frame)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/objprint/frame_analyzer.py", line 20, in get_args
    func_call_str = self.get_executing_function_call_str(frame)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/objprint/frame_analyzer.py", line 58, in get_executing_function_call_str
    source = inspect.getsource(module)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/inspect.py", line 1258, in getsource
    lines, lnum = getsourcelines(object)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/inspect.py", line 1240, in getsourcelines
    lines, lnum = findsource(object)
                  ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/inspect.py", line 1059, in findsource
    file = getsourcefile(object)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/inspect.py", line 936, in getsourcefile
    filename = getfile(object)
               ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/inspect.py", line 897, in getfile
    raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module '__main__'> is a built-in module

If you suspect this is an IPython 8.12.0 bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

@gaogaotiantian
Copy link
Owner

arg_name=True requires the source code access but ipython definitely does something weird when it enters the debugger. If you throw out arg_name=True this should work fine.

@riyadparvez
Copy link
Author

Thank you for the workaround. That being said I do think an exception shouldn't be thrown since this is primarily a debugging tool. Is it possible to just catch the exception and leave the source line empty?

@gaogaotiantian
Copy link
Owner

Yes, TypeError should be caught together with OSError if the source is not available. I will fix it later. Thanks for the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants