Commit e4c52dcf authored by Laurent Peuch's avatar Laurent Peuch
Browse files

feat(fix-deprecated-warnings): handle case where a renaming has been assigned before

parent eb6ff5ff911c
Pipeline #158680 failed with stage
in 1 minute and 18 seconds
......@@ -130,6 +130,28 @@ class FixDeprecatedWarnings(Command):
for call in line("call"):
if call.previous.value == warning["old_name"]:
call.previous.value = warning["new_name"]
# we are probably in a annoying situation where the
# user as wrote something like:
# > old_name = some_object.old_name
# > old_name()
# so we need to find the assignment to rename it
if call.previous.index_on_parent == 0:
for assignment in call.parent_find(("def", "class")).find_all(
"assignment",
target=lambda x: x.dumps() == warning["old_name"],
):
assignment.target = warning["new_name"]
# XXX this is hackish and can fail if
# "old_name" appears several times on the line
# but it should be good enough for now
assignment.value.replace(
assignment.value.dumps().replace(
warning["old_name"], warning["new_name"]
)
)
if "version" and "package" in warning:
versions_to_increase[warning["package"]] = max(
versions_to_increase.get(warning["package"], "0"),
......@@ -162,6 +184,7 @@ class FixDeprecatedWarnings(Command):
versions_to_increase.get(warning["package"], "0"),
warning["version"],
)
assignment.value[-1] = warning["new_name"]
elif not assignment_already_renamed:
......@@ -189,6 +212,7 @@ class FixDeprecatedWarnings(Command):
),
warning["version"],
)
assignment.value[-1] = warning["new_name"]
elif not assignment_already_renamed:
......@@ -205,6 +229,7 @@ class FixDeprecatedWarnings(Command):
"name", value=warning["old_name"], recursive=False
)
if attribute:
if "version" and "package" in warning:
versions_to_increase[warning["package"]] = max(
versions_to_increase.get(warning["package"], "0"),
......@@ -236,6 +261,7 @@ class FixDeprecatedWarnings(Command):
versions_to_increase.get(warning["package"], "0"),
warning["version"],
)
argument.target.value = warning["new_name"]
elif line.find(
"call_argument",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment