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

__dunder_blunder___ support #4592

Closed
gitpushdashf opened this issue May 23, 2023 · 3 comments
Closed

__dunder_blunder___ support #4592

gitpushdashf opened this issue May 23, 2023 · 3 comments
Labels
rule Implementing or modifying a lint rule

Comments

@gitpushdashf
Copy link

Hi, everyone!

I'm not sure if this rule would cover this or not: https://beta.ruff.rs/docs/rules/dunder-function-name/

I made a dunder blunder today, with an extra _. Despite ruff, pyright, and pytest, nothing caught my error. It was for a def __lt__()-type function.

This seems fairly trivial, at first glance, at least compared to other rules. Those extra underscores can really blend in with eachother.

If the dunder-function-name does cover it, maybe it could be documented? Or maybe two separate rules would be ideal?

Anyway, Ruff is an awesome project. I don't know if there's an existing Python tool that does this check.

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label May 24, 2023
@ngnpope
Copy link
Contributor

ngnpope commented May 24, 2023

This is an interesting one. I've also found mistakes like __lte__() instead of the correct __le__(), etc. which would be good to catch. This might be easily done by having a set of known dunders and comparing. Should be easy enough to do a "Did you mean X?" too.

It's worth noting that Python's enum has some custom dunder methods and it may also be good to extend support for the custom sunder methods too? (I've mistakenly used def __missing__(...): instead of def _missing_(...): before.)

@gitpushdashf
Copy link
Author

This is an interesting one. I've also found mistakes like __lte__() instead of the correct __le__(), etc. which would be good to catch. This might be easily done by having a set of known dunders and comparing. Should be easy enough to do a "Did you mean X?" too.

It's worth noting that Python's enum has some custom dunder methods and it may also be good to extend support for the custom sunder methods too? (I've mistakenly used def __missing__(...): instead of def _missing_(...): before.)

Probably! Sunder method mistakes would be good to catch as well.

@charliermarsh charliermarsh added the needs-decision Awaiting a decision from a maintainer label Jul 10, 2023
@charliermarsh
Copy link
Member

I think we now support this via bad-dunder-method-name.

@charliermarsh charliermarsh removed the needs-decision Awaiting a decision from a maintainer label Jan 4, 2024
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

No branches or pull requests

3 participants