-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Resolve used-before-assignment
false negative when a function is defined under TYPE_CHECKING
#10034
Conversation
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #10034 +/- ##
=======================================
Coverage ? 95.80%
=======================================
Files ? 174
Lines ? 18956
Branches ? 0
=======================================
Hits ? 18160
Misses ? 796
Partials ? 0
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cab818f
to
86d91b6
Compare
This comment has been minimized.
This comment has been minimized.
Thanks so much @zenlyj, is this ready for review? |
i don't think the current approach is correct, it silences the check in many cases and something like this is not flagged even though it would blow up in runtime:
|
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.
This comment has been minimized.
This comment has been minimized.
@jacobtylerwalls this is ready for review. let me know if there is anything i missed here, thank you! |
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, thank you, great work. Do you mind adding a fragment for the changelog ? (I'll also let Jacob review before merging).
This comment has been minimized.
This comment has been minimized.
I'll handle the Home Assistant false positive in another PR. |
hey @jacobtylerwalls, i was just thinking about this case:
we should probably raise a message here? |
Good catch, I'm fine with opening a new issue for it. I think it should be real UBA, not "possibly". |
it is worth noting that prior to my changes in this PR, we're emitting |
π€ Effect of this PR on checked open source code: π€ Effect on home-assistant:
This comment was generated for commit 3808c4e |
Hello @zenlyj. You've been doing a lot of great work for pylint lately, including this one, would you be interested in becoming a triager ? (I would normally have asked you privately but your commit mail is a no reply :) ) |
hello, i just dropped you an email, let's talk there |
Type of Changes
Description
Raise
used-before-assignment
when a function is defined underTYPE_CHECKING
and used later.Also extending the nonlocal handling to resolve the following false positive that was discovered by the primer tests, where a variable usage references a nonlocal binding from an outer, enclosing frame.
These changes mainly include a search for nonlocal declarations in all enclosing frames of the variable usage. The idea is to rely on existing nonlocal checks and to only check outer frames if all nodes are filtered out by the consumer.
Refs #10028