(
modname: str, filename: str, expected_number: int, cmd: code_writer_cmd
)
| 38 | |
| 39 | |
| 40 | def 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 | ] |
no test coverage detected