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

Improve filename computation for syntax.dbg #12

Closed
Technologicat opened this issue Aug 8, 2019 · 3 comments
Closed

Improve filename computation for syntax.dbg #12

Technologicat opened this issue Aug 8, 2019 · 3 comments
Labels
discussion Thinking it over - comments welcome! enhancement New feature or request
Milestone

Comments

@Technologicat
Copy link
Owner

Just to mark a future TODO.

The issue with using dbg[] in the REPL is that __file__ is not defined. There's a filename computation in the stdlib's warnings.py that addresses exactly this.

  • Maybe we could adapt the solution for our purposes?
  • Performance implications, may need to run the code at each call site of dbg? Is the REPL support for syntax.dbg worth it?
@Technologicat Technologicat added enhancement New feature or request question Further information is requested labels Aug 8, 2019
@Technologicat Technologicat added this to the far-future milestone Aug 8, 2019
@Technologicat Technologicat added discussion Thinking it over - comments welcome! and removed question Further information is requested labels Aug 8, 2019
@Technologicat Technologicat changed the title Improved filename computation for syntax.dbg Improve filename computation for syntax.dbg Aug 22, 2019
@Technologicat
Copy link
Owner Author

Something as simple as this could work:

def _callsite_filename():
     stack = inspect.stack()
     frame = stack[1].frame
     filename = frame.f_code.co_filename
     del frame, stack
     return filename

@Technologicat
Copy link
Owner Author

Issues cleanup: Now that I have a plan, this is a low-hanging fruit. Let's try to have this in 0.14.2.

@Technologicat Technologicat modified the milestones: , 0.14.2 Feb 27, 2020
@Technologicat
Copy link
Owner Author

And, since it's for debugging, this doesn't need high performance. So having to call inspect.stack for each invocation of dbg shouldn't be a problem.

Least surprise, with fewest caveats, is more important. Fixing this allows us to remove the note from the docs that dbg won't work in the REPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Thinking it over - comments welcome! enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant