2014-12-09 16:19:48 +00:00
|
|
|
# test overriding builtins
|
|
|
|
|
|
|
|
import builtins
|
|
|
|
|
|
|
|
# override generic builtin
|
2017-02-14 21:57:56 +00:00
|
|
|
try:
|
|
|
|
builtins.abs = lambda x: x + 1
|
|
|
|
except AttributeError:
|
|
|
|
print("SKIP")
|
2017-06-10 18:03:01 +01:00
|
|
|
raise SystemExit
|
2017-02-14 21:57:56 +00:00
|
|
|
|
2014-12-09 16:19:48 +00:00
|
|
|
print(abs(1))
|
|
|
|
|
|
|
|
# __build_class__ is handled in a special way
|
2019-07-31 13:34:43 +01:00
|
|
|
orig_build_class = __build_class__
|
2014-12-09 16:19:48 +00:00
|
|
|
builtins.__build_class__ = lambda x, y: ('class', y)
|
|
|
|
class A:
|
|
|
|
pass
|
|
|
|
print(A)
|
2019-07-31 13:34:43 +01: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
|