1# test overriding builtins
2
3import builtins
4
5# override generic builtin
6try:
7    builtins.abs = lambda x: x + 1
8except AttributeError:
9    print("SKIP")
10    raise SystemExit
11
12print(abs(1))
13
14# __build_class__ is handled in a special way
15orig_build_class = __build_class__
16builtins.__build_class__ = lambda x, y: ('class', y)
17class A:
18    pass
19print(A)
20builtins.__build_class__ = orig_build_class
21
22# __import__ is handled in a special way
23def custom_import(name, globals, locals, fromlist, level):
24    print('import', name, fromlist, level)
25    class M:
26        a = 1
27        b = 2
28    return M
29builtins.__import__ = custom_import
30__import__('A', None, None, None, 0)
31import a
32import a.b
33from a import a
34from a.b import a, b
35from .a import a
36from ..a import a, b
37