[Python-Dev] API design question: how to extend sys.settrace()? (original) (raw)

Victor Stinner victor.stinner at gmail.com
Wed Sep 27 08:56:32 EDT 2017


Hi,

In bpo-29400, it was proposed to add the ability to trace not only function calls but also instructions at the bytecode level. I like the idea, but I don't see how to extend sys.settrace() to add a new "trace_instructions: bool" optional (keyword-only?) parameter without breaking the backward compatibility. Should we add a new function instead?

Would it be possible to make the API "future-proof", so we can extend it again later?

I almost never used sys.settrace(), so I prefer to ask on this python-dev list.

Copy of the George King's message: https://bugs.python.org/issue29400#msg298441

""" After reviewing the thread, I'm reminded that the main design problem concerns preserving behavior of this idiom: "old=sys.gettrace(); ...; sys.settrace(old)"

If we add more state, i.e. the trace_instructions bool, then the above idiom no longer correctly stores/reloads the full state.

Here are the options that I see:

  1. New APIs:
  1. Add keyword arg to settrace.
  1. New API, but with extensible keyword args:

As I see it:

Examples of possible future features via keywords:

I intend to prototype one or both of these, but I'm also feeling a bit of time pressure to get the basic feature on track for 3.7. """

settraceinst() doesn't seem "future-proof" to me.

Victor



More information about the Python-Dev mailing list