New submission from Ian H <insertinterestingnameh...@gmail.com>:

Some of the import-related C API functions are documented as bypassing an 
override to builtins.__import__. This appears to be the case, but the 
documentation is incomplete in this regard. For example, PyImport_ImportModule 
is implemented by calling PyImport_Import which does respect an override to 
builtins.__import__, but PyImport_ImportModule doesn't mention respecting an 
override. On the other hand some routines (likeĀ 
PyImport_ImportModuleLevelObject) do not respect an override to the builtin 
import.

Is this something that people are open to having fixed? I've been working on an 
academic project downstream that involved some overrides to the __import__ 
machinery (I haven't figured out a way to do this with just import hooks) and 
having some modules skip going through our override threw us for a bad 
debugging loop. The easiest long-term fix from our perspective is to patch the 
various PyImport routinesĀ to always respect an __import__ override. This 
technically is a backwards compatibility break, but I'm unsure if anyone is 
actually relying on the fact that specific C API functions bypass 
builtins.__import__ entirely. It seems more likely that the current behavior 
will cause bugs downstream like it did for us.

----------
messages: 391220
nosy: Ian.H
priority: normal
severity: normal
status: open
title: C API Functions Bypass __import__ Override
type: behavior
versions: Python 3.9

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

Reply via email to