Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cube-doctor
Commits
f15a884ed589
Commit
e4c52dcf
authored
Oct 28, 2022
by
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
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cube_doctor/transforms/fix_deprecated_warnings.py
View file @
f15a884e
...
...
@@ -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"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment