Ryan Hileman <lunixbo...@gmail.com> added the comment:

I'm definitely not proposing to hook all of object.__getattr__, as my intuition 
says that would be very slow. I simply refer to "object.__getattr__" as the 
event name used by a couple of rare event audit hooks. This is how getting 
__code__ is emitted: 
https://github.com/python/cpython/blob/7301979b23406220510dd2c7934a21b41b647119/Objects/funcobject.c#L250

However, there's not much point in the sys._getframe and func.__code__ family 
of audit hooks right now as tracebacks expose the same information (and may 
even do so accidentally). I am personally interested in these hooks for non 
sandbox reasons in a production application that cares about perf, FWIW.

I think this would be implemented by extending the traceback object's getters 
to include tb_code and tb_frame: 
https://github.com/python/cpython/blob/7301979b23406220510dd2c7934a21b41b647119/Python/traceback.c#L156-L159

I project it won't have any noticeable perf impact (especially if the audit 
hook is written in C), as most reasons to inspect a traceback object will be 
exceptional and not in critical paths.

I'd be happy to write a proposed patch if that would help.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42800>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to