-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix enclosing attribute for attributes in call arguments #362
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zsol for the failed test case, looks like we intended to remove the x.y and keep x.y.z.
If that's the case, then this is not a bug. Can you confirm?
LibCST/libcst/codemod/commands/tests/test_remove_unused_imports.py
Lines 51 to 63 in 6a5e739
def test_dotted_imports(self) -> None: | |
before = """ | |
import a.b, a.b.c | |
import e.f | |
import g.h | |
import x.y, x.y.z | |
def foo() -> None: | |
a.b | |
e.g | |
g.h.i | |
x.y.z | |
""" |
@Kronuz what's your use case that current code doesn't work?
In general, shadow a name in a loop is confusing and may cause bug. If it's possible, we should develop a lint rule to detect it.
99c7f1a
to
1c75064
Compare
I added a test which fails without this: LibCST/libcst/codemod/commands/tests/test_remove_unused_imports.py Lines 80 to 88 in 1c75064
I'm thinking the real reason could also be the incorrect detection of |
Yes that name shadowing was intentional. The first |
import d | ||
|
||
def foo() -> None: | ||
d.x(c(y)).w() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
y
is an undefined name. Shall we just update it to make it valid use case?
@Kronuz, when @zsol added the variable name shadow, he tries to remove the
|
@jimmylai, I think I know what the real problem is. I’ll try to fix it! |
1c75064
to
f5c703b
Compare
@jimmylai, fixed! |
@Kronuz the fix broke a test for rename codemod. LibCST/libcst/codemod/commands/tests/test_rename.py Lines 52 to 67 in 030df06
You can run |
e2a0b54
to
4b54827
Compare
Fixes enclosed arguments like `c.d` in `x.y(c.d()).z()` were badly being resolved as `x.y` instead. This also clarifies the intent in `infer_accesses()` so it no longer shadows variable `name` and also fixes the case where no node is actually found in the scope.
4b54827
to
3e66bdd
Compare
Done! sorry about that :P These fixes will be needed for the linter to work. |
Codecov Report
@@ Coverage Diff @@
## master #362 +/- ##
=======================================
Coverage 94.05% 94.05%
=======================================
Files 231 231
Lines 22093 22101 +8
=======================================
+ Hits 20779 20787 +8
Misses 1314 1314
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Summary
Fixes enclosed arguments like
c.d
inx.y(c.d()).z()
were badly being resolved asx.y
instead.This also clarifies the intent in
infer_accesses()
so it no longer shadows variablename
and also fixes the case where no node is actually found in the scope.Test Plan
Run tests