Fixes duplicate-code check with ignore-imports#9147
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #9147 +/- ##
=======================================
Coverage 95.76% 95.76%
=======================================
Files 173 173
Lines 18680 18681 +1
=======================================
+ Hits 17889 17890 +1
Misses 791 791
|
This comment has been minimized.
This comment has been minimized.
jacobtylerwalls
left a comment
There was a problem hiding this comment.
Thanks for the patch!
Inference seems like overkill here, since we just need to traverse the ast. Something like this passes the unit test you've contributed. It causes a failure in test_no_hide_code_with_imports, but that puzzles me as that expected result looks incorrect (we should remove the --ignore-imports flag from that case, no?
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
jacobtylerwalls
left a comment
There was a problem hiding this comment.
Thanks for the updates; very helpful. Requesting one last test case to pass and then this should be ready to merge!
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit c5cbe23 |
jacobtylerwalls
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
Sure, thank you for the extensive review and suggestions. |
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
We're not checking duplicate-code in the primers, might be beneficial to check locally or exceptionally/temporarily enable it in the CI in this case ? (wdyt @jacobtylerwalls ?)
|
Yeah, that's worth a try. |
|
I ran the primer locally, minus I did see a handful of wanted changes like this: No longer emitted: (astroid) |
|
(Just clarifying for folks who might not be aware of the flakiness in the primer checks: the "noisy, trivial output" I referred to is probably from some unrelated mutability of cached objects in astroid, not from anything wrong in this PR.) |
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com> (cherry picked from commit 67f20bd)
|
Thank you for checking Jacob ! |
Type of Changes
Description
Improves detection of imports under conditionals.
Limited checks by constant conditions such asTrue/typing.TYPE_CHECKING.Closes #8914