summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/fun_code.py
blob: 59e1f7ec0483dcc09dc11adac214cd8b4e34cc24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Test function.__code__ attribute.

try:
    (lambda: 0).__code__
except AttributeError:
    print("SKIP")
    raise SystemExit


def f():
    return a


ftype = type(f)

# Test __code__ access and function constructor.
code = f.__code__
print(type(ftype(code, {})) is ftype)

# Test instantiating multiple code's with different globals dicts.
code = f.__code__
f1 = ftype(code, {"a": 1})
f2 = ftype(code, {"a": 2})
print(f1(), f2())

# Test bad first argument type.
try:
    ftype(None, {})
except TypeError:
    print("TypeError")

# Test bad second argument type.
try:
    ftype(f.__code__, None)
except TypeError:
    print("TypeError")