Skip to content
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

Ignore annotated lambdas in class scopes #10720

Merged
merged 1 commit into from Apr 1, 2024
Merged

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
Copy link

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
17 checks passed
@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