Remove repeating module names from string. Arguments: task_name (str): Task name (full path including module), to use as the basis for removing module names. s (str): The string we want to work on. Example: >>> _shorten_names( ... 'x.tasks.ad
(substr: str, s: str)
| 154 | |
| 155 | |
| 156 | def remove_repeating(substr: str, s: str) -> str: |
| 157 | """Remove repeating module names from string. |
| 158 | |
| 159 | Arguments: |
| 160 | task_name (str): Task name (full path including module), |
| 161 | to use as the basis for removing module names. |
| 162 | s (str): The string we want to work on. |
| 163 | |
| 164 | Example: |
| 165 | |
| 166 | >>> _shorten_names( |
| 167 | ... 'x.tasks.add', |
| 168 | ... 'x.tasks.add(2, 2) | x.tasks.add(4) | x.tasks.mul(8)', |
| 169 | ... ) |
| 170 | 'x.tasks.add(2, 2) | add(4) | mul(8)' |
| 171 | """ |
| 172 | # find the first occurrence of substr in the string. |
| 173 | index = s.find(substr) |
| 174 | if index >= 0: |
| 175 | return ''.join([ |
| 176 | # leave the first occurrence of substr untouched. |
| 177 | s[:index + len(substr)], |
| 178 | # strip seen substr from the rest of the string. |
| 179 | s[index + len(substr):].replace(substr, ''), |
| 180 | ]) |
| 181 | return s |
| 182 | |
| 183 | |
| 184 | StringIO = io.StringIO |
no test coverage detected