Here's a script to find places where this proposal could be useful. Try it on a directory.
```python
import ast
import linecache
import sys
from pathlib import Path
root = Path(sys.argv[1])
def main():
for path in root.rglob("**/*.py"):
source = path.read_text()
try:
tree = ast.parse(source)
except SyntaxError:
continue
for node in ast.walk(tree):
if isinstance(node, ast.Call):
def is_same_name(keyword: ast.keyword):
return (
isinstance(keyword.value, ast.Name)
and keyword.value.id == keyword.arg
)
args = node.keywords
elif isinstance(node, ast.Dict):
def is_same_name(pair):
key, value = pair
return (
isinstance(value, ast.Name) and
isinstance(key, (ast.Constant, ast.Str)) and
value.id == key.s
)
args = zip(node.keys, node.values)
else:
continue
threshold = 3
if sum(map(is_same_name, args)) < threshold:
continue
print(f'File "{path}", line {node.lineno}')
for lineno in range(node.lineno, node.end_lineno + 1):
print(linecache.getline(str(path), lineno), end="")
print()
main() ```