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

More rules out of stub author's control #14535

Open
Samuel-Therrien-Beslogic opened this issue Nov 22, 2024 · 7 comments
Open

More rules out of stub author's control #14535

Samuel-Therrien-Beslogic opened this issue Nov 22, 2024 · 7 comments
Labels
accepted Ready for implementation help wanted Contributions especially welcome rule Implementing or modifying a lint rule

Comments

@Samuel-Therrien-Beslogic
Copy link

Samuel-Therrien-Beslogic commented Nov 22, 2024

Ruff 0.8.0 ignores ambiguous-variable-name (E741) automatically in pyi files. This prompted me to look at other rules I disable specifically for .pyi files and found the following which I think should apply in all cases:

I haven't gone back and validated if these still trigger in stub files since I added them to our shared config, sorry if I tagged a rule that's already ignored.

@AlexWaygood
Copy link
Member

Thanks! Your analysis all seems correct to me. I'd happily accept PRs disapplying these rules to stub files.

For E741 we were quite cautious, and made the change preview-only for several minor releases before stabilising the change. I don't think we need to be as cautious this time around. Our versioning policy states that it's fine to apply changes in patch releases if they reduce scope (and these would be reductions in scope); we only need to wait for a minor release if a change increases the scope of a rule.

@AlexWaygood AlexWaygood added rule Implementing or modifying a lint rule accepted Ready for implementation help wanted Contributions especially welcome labels Nov 22, 2024
@dylwil3
Copy link
Collaborator

dylwil3 commented Nov 22, 2024

The linked PR is for all but the last two bullets since those were suggested with less oomph 😄

dylwil3 added a commit that referenced this issue Nov 23, 2024
This PR causes the following rules to ignore stub files, on the grounds
that it is not under the author's control to appease these lints:

- `PLR0904` https://docs.astral.sh/ruff/rules/too-many-public-methods/
- `PLR0913` https://docs.astral.sh/ruff/rules/too-many-arguments/
- `PLR0917`
https://docs.astral.sh/ruff/rules/too-many-positional-arguments/
- `PLW3201` https://docs.astral.sh/ruff/rules/bad-dunder-method-name/
- `SLOT` https://docs.astral.sh/ruff/rules/#flake8-slots-slot
- `FBT` https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
(except for FBT003 since that involves a function call.)

Progress towards #14535
@InSyncWithFoo
Copy link
Contributor

@dylwil3 Is this issue resolved or is there something left to be done?

@dylwil3
Copy link
Collaborator

dylwil3 commented Nov 24, 2024

I leave that to @Samuel-Therrien-Beslogic to decide - as I said, I did not do anything regarding the last two bullet points. So it depends on whether there is interest in continuing to discuss those items.

@Samuel-Therrien-Beslogic
Copy link
Author

Samuel-Therrien-Beslogic commented Nov 24, 2024

Thanks @dylwil3 !

For PLC2701, I think that some users may still want a warning about using private names that are subject to change and suddenly break a stub, as per:

Further, as private imports are not considered part of the public API, they are prone to unexpected changes, especially outside of semantic versioning.

Instead, consider using the public API of the module.

But also

This rule ignores private name imports that are exclusively used in type annotations. Ideally, types would be public; however, this is not always possible when using third-party libraries.

(that last sentence is why I've been ignoring it, since more often then not there's no alternatives other than re-writing Aliases, TypeVars and Protocols)

So I'm not 100% convinced either way whether this should be disabled for everyone.


flake8-builtins (A)

The following I'm pretty sure should be disabled in stubs:

As for the rest:

@harahu
Copy link

harahu commented Dec 4, 2024

Just wanted to chime in and say that most if not all of the pep8-naming (N) rules should probably not be applied to stub files either.

@Avasam
Copy link
Contributor

Avasam commented Dec 24, 2024

I did an experiment where I enabled nearly all rules in typeshed, and here's what I found typeshed would disable in PYI files (that isn't just an opinionated matter): https://github.com/Avasam/typeshed/pull/39/files#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711

As for opinionated rules: RUF022, RUF023, F403, F405 (caught by type-checkers), FURB180 (often breaks mypy/stubtest) are disabled for reasons specific to typeshed and can be kept out of this conversation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation help wanted Contributions especially welcome rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

6 participants