James Lu wrote:
> Minimal strawman proposal. New keyword debug.
> debug EXPRESSION
> Executes EXPRESSION when in debug mode.
> debug context
> Prints all the variables of the enclosing closure and all the variable names
> accessed
> within that block. For example, if in foo you access the global variable
> spam, spam would
> be printed. The format would be:
Wouldn't be dropping into PDB more efficient here? Anyway you could still use
something like `inspect.stack()` and inspect the closure of the function.
Together with a dedicated variable (from OS or via argv) you could distinguish
between debug and non-debug mode.
> variableName: value
> variableTwo: value
> where "value" is the repr() of the variable.
> Separated by new lines. The exact output format would not be part of the spec.
> ?identifier
> would print "identifier: value." Repr as before. Using this in non-debug mode
> emits a
> warning.
This you can do in Python 3.8 via f-strings:
[`f'{indentifier=}`](https://docs.python.org/3.8/whatsnew/3.8.html#f-strings-now-support-for-quick-and-easy-debugging)
> ?identifier.property.property
> is also valid.
> A new property descriptor on the global variable, “debugger.” This is an
> alias for
> importing PDB and causing the debugger to pause there.
This is possible via
[`breakpoint`](https://docs.python.org/3/library/functions.html#breakpoint).
> The behavior of this descriptor in non-debug mode is TBD.
> Debug mode may be specified per-module at interpreter launch.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/XLWLMQ4WIOKF7QQDL4U5F6W4ETEPUXRH/
Code of Conduct: http://python.org/psf/codeofconduct/