[pyflakes] Fix false positive for __class__ in lambda expressions within class definitions (F821)#20564
Conversation
|
ntBre
left a comment
There was a problem hiding this comment.
Thank you! The tests look good, but what do you think about moving the new code to visit_expr to mirror the function version a bit more closely?
|
Yeah, that approach makes sense to me. Thanks for the review! |
|
Hmm, it looks like there are some new false positives in the ecosystem report. I was hoping it was something simple with the scope popping, which is why I pushed a commit, but that didn't end up helping. We're flagging a case like this with F401: import uuid
class C:
uuid = lambda: str(uuid.uuid4())and I don't fully understand why. We'll need to figure it out before we can merge this, though. Would you mind taking a look? |
Refactors the handling of implicit __class__ scopes in lambdas to only add the DunderClassCell scope when a lambda is nested within a class, not just any lambda. Adds a test case to ensure lambdas referencing module-level variables are not incorrectly flagged as F821.
|
The issue was that the I fixed it by moving the scope logic from |
|
Ah okay, I guess my earlier suggestion about moving it to |
Summary
Fixes #20562