Debian Codegraph @

friendly_traceback/runtime_errors/_attribute_getter.py

raw symbols SCIP
1 """Helper script to obtain a list of available attributes for each modules.
2
3 This is not meant to be imported anywhere.
4
5 The output is shown in the console. It should be saved in
6 modules_attributes.py located in this directory.
7 """
8
9 import sys
10 from pprint import pprint
11
12 from stdlib_modules import names
13
14 all_attributes = {}
15 for mod_name in names:
16 # List compiled with Python 3.9
17 if mod_name in [
18 "antigravity", # has side-effects
19 "binhex", # deprecated
20 "formatter", # deprecated
21 "imp", # deprecated
22 "parser", # deprecated
23 "symbol", # deprecated
24 "this", # has side-effects
25 ]:
26 continue
27 try:
28 imported_mod = __import__(mod_name)
29 except ImportError:
30 continue
31 for attr_name in dir(imported_mod):
32 if attr_name.startswith("_") or len(attr_name) == 1:
33 continue
34 elif attr_name in names and attr_name != mod_name:
35 continue
36 elif attr_name in all_attributes:
37 all_attributes[attr_name].append(mod_name)
38 else:
39 all_attributes[attr_name] = [mod_name]
40
41 with open("modules_attributes.py", "w") as f:
42 f.write(f"# Created with {sys.version_info}\n")
43 f.write("attribute_names = ")
44 pprint(all_attributes, stream=f, indent=4)