Created
August 20, 2019 16:02
-
-
Save hltbra/9ac5e76b83bb5a6ed282b583a64924d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ast | |
code = """ | |
import foo | |
a = 1 + 2 | |
b = "a" + "b" * 3 | |
func(1, "a", b=1, c="c") | |
hello({}, [], "a", "b") | |
func(1, specialarg="test2") | |
func(2) | |
""" | |
result = ast.parse(code) | |
for node in ast.walk(result): | |
if isinstance(node, ast.Expr): | |
if isinstance(node.value, ast.Call): | |
func_name = node.value.func.id | |
for keyword in node.value.keywords: | |
if func_name == "func" and keyword.arg == "specialarg": | |
print(f'WARNING: "specialarg" on line number {node.lineno}') | |
print("--------") | |
for lineno, line in enumerate(code.splitlines(), start=1): | |
print(f"{lineno:3} | {line}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment