MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / process_module

Function process_module

tools/generate_tuple_map_overloads.py:40–131  ·  view source on GitHub ↗
(
    modname: str, filename: str, expected_number: int, cmd: code_writer_cmd
)

Source from the content-addressed store, hash-verified

38
39
40def process_module(
41 modname: str, filename: str, expected_number: int, cmd: code_writer_cmd
42) -> str:
43 # use tempfile in same path as the module, or at least in the
44 # current working directory, so that black / zimports use
45 # local pyproject.toml
46 found = 0
47 with (
48 NamedTemporaryFile(
49 mode="w",
50 delete=False,
51 suffix=".py",
52 ) as buf,
53 open(filename) as orig_py,
54 ):
55 indent = ""
56 in_block = False
57 current_fnname = given_fnname = None
58 for line in orig_py:
59 m = re.match(
60 r"^( *)# START OVERLOADED FUNCTIONS ([\.\w_]+) ([\w_]+) (\d+)-(\d+)(?: \"(.+)\")?", # noqa: E501
61 line,
62 )
63 if m:
64 found += 1
65 indent = m.group(1)
66 given_fnname = current_fnname = m.group(2)
67 if current_fnname.startswith("self."):
68 use_self = True
69 current_fnname = current_fnname.split(".")[1]
70 else:
71 use_self = False
72 return_type = m.group(3)
73 start_index = int(m.group(4))
74 end_index = int(m.group(5))
75 extra_args = m.group(6) or ""
76
77 cmd.write_status(
78 f"Generating {start_index}-{end_index} overloads "
79 f"attributes for "
80 f"class {'self.' if use_self else ''}{current_fnname} "
81 f"-> {return_type}\n"
82 )
83 in_block = True
84 buf.write(line)
85 buf.write(
86 "\n # code within this block is "
87 "**programmatically, \n"
88 " # statically generated** by"
89 f" tools/{os.path.basename(__file__)}\n\n"
90 )
91
92 for num_args in range(start_index, end_index + 1):
93 ret_suffix = ""
94 combinations = [
95 f"__ent{arg}: _TCCA[_T{arg}]"
96 for arg in range(num_args)
97 ]

Callers 1

run_moduleFunction · 0.70

Calls 8

openFunction · 0.85
splitMethod · 0.80
write_statusMethod · 0.80
matchMethod · 0.45
startswithMethod · 0.45
writeMethod · 0.45
replaceMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected