Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hltbra
Created August 20, 2019 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hltbra/9ac5e76b83bb5a6ed282b583a64924d5 to your computer and use it in GitHub Desktop.
Save hltbra/9ac5e76b83bb5a6ed282b583a64924d5 to your computer and use it in GitHub Desktop.
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