Skip to content

Ignore annotated lambdas in class scopes#10720

Merged
charliermarsh merged 1 commit intomainfrom
charlie/lambda-pos
Apr 1, 2024
Merged

Ignore annotated lambdas in class scopes#10720
charliermarsh merged 1 commit intomainfrom
charlie/lambda-pos

Conversation

@charliermarsh
Copy link
Member

Summary

An annotated lambda assignment within a class scope is often intentional. For example, within a dataclass or Pydantic model, these are treated as fields rather than methods (and so can be passed values in constructors).

I originally wrote this to special-case dataclasses and Pydantic models... But was left feeling like we'd see more false positives here for little gain (an annotated lambda within a class is likely intentional?). Open to opinions, though.

Closes #10718.

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Apr 1, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

What a weird edge case. This makes sense to me!

@charliermarsh charliermarsh merged commit d36f609 into main Apr 1, 2024
@charliermarsh charliermarsh deleted the charlie/lambda-pos branch April 1, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E731: Lambda default value for a Callable dataclass field is incorrectly flagged as lambda assignment

2 participants