-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Define the interface of a CodeLike object #117087
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
Comments
So basically the CodeLike object is a Python object for Python libraries to get information right? If it complies to the existing monitoring callback, then we'd expect any callback function to work even with the CodeLike object - but that's not entirely possible right? The user using Or we are actually talking about a useful object that can provide some information about the code, which could be used by a variaty of tools? For example, when cython triggers a monitoring event |
The main purpose of the code-like object, from the perspective of tools, is to convert a We also want to support the instrospection method/attributes of code objects, and with the same names for ease of porting for coverage.py, profile, etc. So, how about this: class CodeLike(metaclass=ABCMeta):
@abstractmethod
def offset_to_location(self, offset):
"""Returns the 5-tuple (filename, startline, startcolumn, endline, endcolumn) for the given offset.
May return None if the offset is valid, but there is no location information for it.
If the offset is not valid, a ValueError should be raised"""
@abstractproperty
def co_name(self):
"The (short) name of this callable"
@abstractproperty
def co_qualname(self):
"The full, qualified name of this callable"
@abstractproperty
def co_filename(self):
"The name of the primary file defining this callable"
@abstractproperty
def co_argcount(self):
"The maximum number of arguments for this callable"
@abstractproperty
def co_posonlyargcount(self):
"The number of positional only arguments for this callable"
@abstractproperty
def co_kwonlyargcount(self):
"The maximum of keyword only arguments for this callable" |
My impression is that most code that uses tracing currently expects a real cpython/Python/instrumentation.c Lines 1611 to 1630 in de19694
Can't we split the The current |
In the Changing the callback signature to expect To support class CodeLike(metaclass=ABCMeta):
...
@abstractmethod
def __get_local_events__(self, tool_id: int) -> int:
"""Gets the local events set previously set by __set_local_events__.
Called by sys.monitoring.get_local_events(tool_id, self)"""
@abstractmethod
def __set_local_events__(self, tool_id: int, event_set: int) -> None:
"Sets the local events. Called by sys.monitoring.set_local_events(tool_id, self, event_set)" |
I'm a tool author, but a bit lost on what is being asked of me here. Coverage.py now fully supports branch coverage using sys.monitoring as it is. |
@nedbat We are asking what part of the code object API does coverage (and other tools that use sys.monitoring) actually use, and how easy or difficult would it be to change to use only the API proposed above. For example, does coverage use the |
Things coverage.py does with code objects:
I don't use |
The C API for monitoring (#111997) works with code-like objects, so that the user is not required to create a CodeObject where there isn't one already.
We need to define the Python API of a CodeLike so that it's useful for tools that use monitoring. This issue is to define which fields of CodeObject we want to have on a CodeLike.
@markshannon @scoder @nedbat @gaogaotiantian
Linked PRs
The text was updated successfully, but these errors were encountered: