Недавно попробовал небольшим кодом перегрузить стандартный import, чтоб посмотреть детальнее как он работает
remake_import = [(_______)for(_,_in,_for)in((__builtins__,isinstance,dict),)for(_____)in("__import__",)for(__,___)in((_[_____],_.__setitem__,)if(_in(_, _for))else(_.__import__,_.__setattr__,),)for(_______)in((lambda ____:___(_____,(lambda *______:____(__,*______)))),)][0_0]
a = []
def check_import_list(st_import, *import_data):
a.append((import_data[0],import_data[3]))
return st_import(*import_data)
remake_import(check_import_list)
import random
print(a)
Получаем Output:
[('random', None), ('_io', []), ('warnings', ('warn',)), ('math', ('log', 'exp', 'pi', 'e', 'ceil')),
('math', ('sqrt', 'acos', 'cos', 'sin')), ('math', ('tau', 'floor', 'isfinite')), ('os', ('urandom',)),
('_collections_abc', ('Set', 'Sequence')), ('operator', ('index',)), ('itertools', ('accumulate', 'repeat')),
('bisect', ('bisect',)), ('_io', []), ('_bisect', ('*',)), ('os', None), ('_random', None), ('_sha512', ('sha512',))]
Откуда появляется импорт _io?
Импорты которые присутствуют в исходнике cpython/random.py:
from warnings import warn as _warn
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from math import tau as TWOPI, floor as _floor, isfinite as _isfinite
from os import urandom as _urandom
from _collections_abc import Set as _Set, Sequence as _Sequence
from operator import index as _index
from itertools import accumulate as _accumulate, repeat as _repeat
from bisect import bisect as _bisect
import os as _os
import _random
from _sha512 import sha512 as _sha512