Repository navigation
Fix __class__ binding in class-body lambdas - #11541
Rich Chiodo (rchiodo) merged 1 commit into
Conversation
|
@microsoft-github-policy-service agree |
|
🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR. |
|
|
||
|
|
||
| class A: | ||
| get_class = lambda: __class__ |
There was a problem hiding this comment.
📍 packages/pyright-internal/src/tests/samples/lambda16.py:7
The sample only asserts the happy path. Since the only real risk of this change is over-binding __class__, add a negative case — a module-level or free-function g = lambda: __class__ wired as a second sample expecting validateResults(..., 1) — so a future regression that over-broadens the binding is actually caught. The Skeptic verified this case is correct today (CPython raises NameError, and getEnclosingClass returns undefined), but it isn't locked by a test.
[verified]
|
Looks good — correct, minimal fix for the PEP 3135 |
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
11e80dd to
9ba9719
Compare
|
Thanks for the suggestion. I rebased onto the current
The updated commit has been pushed to the PR branch. |
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
|
Diff from mypy_primer, showing the effect of this PR on open source code: sympy (https://github.com/sympy/sympy)
- .../projects/sympy/sympy/solvers/diophantine/tests/test_diophantine.py:314:30 - error: Cannot access attribute "as_independent" for class "Basic"
- Attribute "as_independent" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/diophantine/tests/test_diophantine.py:380:15 - error: Operator "*" not supported for "None" (reportOptionalOperand)
- .../projects/sympy/sympy/solvers/diophantine/tests/test_diophantine.py:383:13 - error: No overloads for "__init__" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/diophantine/tests/test_diophantine.py:383:18 - error: Argument of type "list[Iterator[Unknown]]" cannot be assigned to parameter "iterable" of type "Iterable[list[bytes]]" in function "__init__" (reportArgumentType)
- .../projects/sympy/sympy/solvers/diophantine/tests/test_diophantine.py:383:30 - error: Cannot access attribute "as_independent" for class "Basic"
- Attribute "as_independent" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/diophantine/tests/test_diophantine.py:383:78 - error: "args" is not a known attribute of "None" (reportOptionalMemberAccess)
- 38271 errors, 82 warnings, 0 informations
+ 38265 errors, 82 warnings, 0 informations
|
Summary
__class__symbol in lambda scopes enclosed by a classclass A: get_class = lambda: __class__Testing
typeEvaluator1.test.ts(159 passed)pyright-internalsuite (62 suites, 2541 tests passed)Fixes #11511