Skip to content

Conversation

danparizher
Copy link
Contributor

Summary

Fixes #20562

Copy link
Contributor

github-actions bot commented Sep 25, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+3 -0 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)

apache/airflow (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

+ task-sdk/src/airflow/sdk/execution_time/comms.py:56:20: TC003 Move standard library import `socket.socket` into a type-checking block

langchain-ai/langchain (+2 -0 violations, +0 -0 fixes)

+ libs/langchain/langchain/indexes/_sql_record_manager.py:19:8: F401 [*] `uuid` imported but unused
+ libs/langchain/langchain/indexes/_sql_record_manager.py:62:5: F811 Redefinition of unused `uuid` from line 19: `uuid` redefined here

Changes by rule (3 rules affected)

code total + violation - violation + fix - fix
TC003 1 1 0 0 0
F401 1 1 0 0 0
F811 1 1 0 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+3 -0 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)

apache/airflow (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

+ task-sdk/src/airflow/sdk/execution_time/comms.py:56:20: TC003 Move standard library import `socket.socket` into a type-checking block

langchain-ai/langchain (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ libs/langchain/langchain/indexes/_sql_record_manager.py:19:8: F401 [*] `uuid` imported but unused
+ libs/langchain/langchain/indexes/_sql_record_manager.py:62:5: F811 Redefinition of unused `uuid` from line 19: `uuid` redefined here

Changes by rule (3 rules affected)

code total + violation - violation + fix - fix
TC003 1 1 0 0 0
F401 1 1 0 0 0
F811 1 1 0 0 0

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

// Here we add the implicit scope surrounding a lambda which allows code in the
// lambda to access `__class__` at runtime when the lambda is defined within a class.
// See the `ScopeKind::DunderClassCell` docs for more information.
let added_dunder_class_scope = if self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was picturing this in visit_stmt like we did for function definitions rather than in the deferred visit. I guess lambdas aren't statements, so the analogous code would actually fit here in visit_expr:

// Visit the default arguments, but avoid the body, which will be deferred.
if let Some(parameters) = parameters {
for default in parameters
.iter_non_variadic_params()
.filter_map(|param| param.default.as_deref())
{
self.visit_expr(default);
}
}
self.semantic.push_scope(ScopeKind::Lambda(lambda));
self.visit.lambdas.push(self.semantic.snapshot());
self.analyze.lambdas.push(self.semantic.snapshot());

I think that should work because we push a lambda snapshot that gets used here like we do for functions. The one downside is that the popping for lambdas happens a bit farther down, unlike functions:

self.analyze.scopes.push(self.semantic.scope_id);
self.semantic.pop_scope();

@danparizher
Copy link
Contributor Author

Yeah, that approach makes sense to me. Thanks for the review!

@danparizher danparizher requested a review from ntBre September 26, 2025 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

F821 false positive for __class__ in lambda expression in class definition
2 participants