2014-12-09 11:19:48 -05:00
|
|
|
# test overriding builtins
|
|
|
|
|
|
|
|
import builtins
|
|
|
|
|
|
|
|
# override generic builtin
|
2017-02-14 16:57:56 -05:00
|
|
|
try:
|
|
|
|
builtins.abs = lambda x: x + 1
|
|
|
|
except AttributeError:
|
|
|
|
print("SKIP")
|
2017-06-10 13:03:01 -04:00
|
|
|
raise SystemExit
|
2017-02-14 16:57:56 -05:00
|
|
|
|
2014-12-09 11:19:48 -05:00
|
|
|
print(abs(1))
|
|
|
|
|
|
|
|
# __build_class__ is handled in a special way
|
2019-07-31 08:34:43 -04:00
|
|
|
orig_build_class = __build_class__
|
2014-12-09 11:19:48 -05:00
|
|
|
builtins.__build_class__ = lambda x, y: ('class', y)
|
|
|
|
class A:
|
|
|
|
pass
|
|
|
|
print(A)
|
2019-07-31 08:34:43 -04:00
|
|
|
builtins.__build_class__ = orig_build_class
|
|
|
|
|
|
|
|
# __import__ is handled in a special way
|
|
|
|
def custom_import(name, globals, locals, fromlist, level):
|
|
|
|
print('import', name, fromlist, level)
|
|
|
|
class M:
|
|
|
|
a = 1
|
|
|
|
b = 2
|
|
|
|
return M
|
|
|
|
builtins.__import__ = custom_import
|
|
|
|
__import__('A', None, None, None, 0)
|
|
|
|
import a
|
|
|
|
import a.b
|
|
|
|
from a import a
|
|
|
|
from a.b import a, b
|
|
|
|
from .a import a
|
|
|
|
from ..a import a, b
|