forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin_dir.py
More file actions
46 lines (28 loc) · 816 Bytes
/
builtin_dir.py
File metadata and controls
46 lines (28 loc) · 816 Bytes
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
37
38
39
40
41
42
43
44
45
46
assert isinstance(dir(), list)
assert "__builtins__" in dir()
class A:
def test():
pass
a = A()
assert "test" in dir(a), "test not in a"
assert "test" in dir(A), "test not in A"
a.x = 3
assert "x" in dir(a), "x not in a"
class B(A):
def __dir__(self):
return ("q", "h")
# Gets sorted and turned into a list
assert ["h", "q"] == dir(B())
# This calls type.__dir__ so isn't changed (but inheritance works)!
assert "test" in dir(A)
# eval() takes any mapping-like type, so dir() must support them
# TODO: eval() should take any mapping as locals, not just dict-derived types
class A(dict):
def __getitem__(self, x):
return dir
def keys(self):
yield 6
yield 5
assert eval("dir()", {}, A()) == [5, 6]
import socket
assert "AF_INET" in dir(socket)