File: _attribute_getter.py

package info (click to toggle)
python-friendly-traceback 0.7.62%2Bgit20240811.d7dbff6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,264 kB
  • sloc: python: 21,500; makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download
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
"""Helper script to obtain a list of available attributes for each modules.

This is not meant to be imported anywhere.

The output is shown in the console. It should be saved in
modules_attributes.py located in this directory.
"""

import sys
from pprint import pprint

from stdlib_modules import names

all_attributes = {}
for mod_name in names:
    # List compiled with Python 3.9
    if mod_name in [
        "antigravity",  # has side-effects
        "binhex",  # deprecated
        "formatter",  # deprecated
        "imp",  # deprecated
        "parser",  # deprecated
        "symbol",  # deprecated
        "this",  # has side-effects
    ]:
        continue
    try:
        imported_mod = __import__(mod_name)
    except ImportError:
        continue
    for attr_name in dir(imported_mod):
        if attr_name.startswith("_") or len(attr_name) == 1:
            continue
        elif attr_name in names and attr_name != mod_name:
            continue
        elif attr_name in all_attributes:
            all_attributes[attr_name].append(mod_name)
        else:
            all_attributes[attr_name] = [mod_name]

with open("modules_attributes.py", "w") as f:
    f.write(f"# Created with {sys.version_info}\n")
    f.write("attribute_names = ")
    pprint(all_attributes, stream=f, indent=4)