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

[pylint] Detect nested methods correctly (PLW1641) #15032

Merged
merged 9 commits into from
Dec 30, 2024

Conversation

InSyncWithFoo
Copy link
Contributor

Summary

Resolves #14882.

Test Plan

cargo nextest run and cargo insta test.

Copy link
Contributor

github-actions bot commented Dec 17, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

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

astropy/astropy (+3 -0 violations, +0 -0 fixes)

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

+ astropy/modeling/parameters.py:113:7: PLW1641 Object does not implement `__hash__` method
+ astropy/table/bst.py:90:7: PLW1641 Object does not implement `__hash__` method
+ astropy/table/column.py:1164:7: PLW1641 Object does not implement `__hash__` method

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PLW1641 3 3 0 0 0

@MichaReiser
Copy link
Member

MichaReiser commented Dec 18, 2024

I'm a bit concerned about special casing this behavior only for PLW1641. Other rules that need to inspect a class's methods, like #14688, will now have inconsistent behavior.

I wonder if we could make this more reusable so that all class method rules could profit from it. Although I'm not quiet sure how to do that.

For example, we could create a any_method function in semantic/analyze/class

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

I refactored your code and introduced a reusable any_member_declaration as discussed in the PR before. The reason why I prefer having this helper is that it now can be used for other rules as well. For example, too many public methods could make use of it, resulting in more consistent behavior across our rules.

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels Dec 30, 2024
@MichaReiser MichaReiser merged commit 2a1aa29 into astral-sh:main Dec 30, 2024
21 checks passed
@MichaReiser
Copy link
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(🐞) PLW1641 not reported if method defined within if
2 participants