Skip to content

Suggestion: adding parameter to configure the frame depth #97

Description

@aroberge

First of all: I just discover devtools and I think it is a fantastic tool. I definitely plan to use it instead of my simple minded debugging helper.

Currently, debug() is assumed to be called explicitly in a given module, with a hard-coded value for the frame in which it looks for information:

    def _process(self, args, kwargs) -> DebugOutput:
        """
        BEWARE: this must be called from a function exactly 2 levels below the top of the stack.
        """
        # HELP: any errors other than ValueError from _getframe? If so please submit an issue
        try:
            call_frame: 'FrameType' = sys._getframe(2)
        except ValueError:
            ...

I would find it useful if the constant 2 could be a configurable parameter. For example, I could then define custom functions like the following:

def handle_problem(*args, **kwargs):
    if dev_version:
        debug = Debug(additional_frame_depth=1)
        debug(*args, **kwargs)
    else:
        print("Internal problem: please report this case.")

Obviously, I could currently do this by subclassing Debug, but I think that this might be a useful feature to have. I understand that the idea is to use devtools.debug during development and one would normally remove all traces of it for releases. However, I find it useful in one of my projects (friendly-traceback) to leave in place such debugging functions such that end-users are never exposed to tracebacks generated by my own project while still being able to cope with the unexpected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions