Skip to content

Commit

Permalink
Only handle TOKEN.NUMBER and TOKEN.STRING
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Algarvio <[email protected]>
  • Loading branch information
s0undt3ch committed Jun 18, 2023
1 parent a75e0d0 commit 77eb5c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/saltrewrite/salt/fix_warn_until.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,28 @@ def rewrite(paths, interactive=False, silent=False):
)
"""
)
.filter(filter_versions)
.modify(fix_warn_unil_version)
.execute(write=True, interactive=interactive, silent=silent)
)


def filter_versions(node, capture, filename):
"""
If the first child is a docstring, process it
"""
arglist = capture["function_arguments"][0]
warn_until_version_argument = arglist.children[0]
if warn_until_version_argument.type == TOKEN.NUMBER:
# For example, 3008, 3009.0
return True
if warn_until_version_argument.type == TOKEN.STRING:
# For example, "3008", "Aragon"
return True
# Don't process node
return False


def fix_warn_unil_version(node, capture, filename):
"""
Automaticaly run fixes against docstrings
Expand Down
16 changes: 16 additions & 0 deletions tests/salt/test_warn_until.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def two():
def three():
warn_until(3008.0, "Code deprecated in 3008.0")
print("one")
def four():
warn_until("3008", "Code deprecated in 3008.0")
print("one")
"""
)
expected_code = textwrap.dedent(
Expand All @@ -37,6 +41,10 @@ def two():
def three():
warn_until(3008.0, "Code deprecated in 3008.0")
print("one")
def four():
warn_until(3008.0, "Code deprecated in 3008.0")
print("one")
"""
)
fpath = tempfiles.makepyfile(code, prefix="test_")
Expand All @@ -62,6 +70,10 @@ def two():
def three():
salt.utils.versions.warn_until(3008.0, "Code deprecated in 3008.0")
print("one")
def four():
salt.utils.versions.warn_until("3008", "Code deprecated in 3008.0")
print("one")
"""
)
expected_code = textwrap.dedent(
Expand All @@ -79,6 +91,10 @@ def two():
def three():
salt.utils.versions.warn_until(3008.0, "Code deprecated in 3008.0")
print("one")
def four():
salt.utils.versions.warn_until(3008.0, "Code deprecated in 3008.0")
print("one")
"""
)
fpath = tempfiles.makepyfile(code, prefix="test_")
Expand Down

0 comments on commit 77eb5c5

Please sign in to comment.