Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make E741 not apply to stub files #10569

Open
AlexWaygood opened this issue Mar 25, 2024 · 2 comments
Open

Make E741 not apply to stub files #10569

AlexWaygood opened this issue Mar 25, 2024 · 2 comments
Labels
linter Related to the linter rule Implementing or modifying a lint rule
Milestone

Comments

@AlexWaygood
Copy link
Member

I think it would make sense to have E741 (ambiguous-variable-name) not apply to stub files.

Unlike with runtime .py files, stub authors generally have no control over the names of variables that appear in a stub. A well-written stub should aim to faithfully represent the interface of the equivalent .py file as it exists at runtime, and that includes any ambiguously named variables in the runtime module. Even if the source code for the stubs is located in the same repository as the runtime module being stubbed, you likely won't be able to change an ambiguously named variable in the stub without also changing the corresponding runtime module, and tools like stubtest will generally help stub authors ensure consistency between the runtime module and the stub.

Typeshed has always ignored this rule for .pyi files in our ruff config (and before that, in our .flake8 config), and I can't think of a situation in which it would be useful when applied to stubs.

Would we need some kind of deprecation period for this change? Or could we just make it?

(F403 and F405 (regarding * imports) similarly flag things that are out of the control of stub authors. But these rules highlight places where ruff's inference capabilities will be severely limited due to the specific idioms being used, so I think we should probably keep these enabled by default, even for .pyi files.)

@AlexWaygood AlexWaygood added rule Implementing or modifying a lint rule linter Related to the linter labels Mar 25, 2024
@charliermarsh
Copy link
Member

I think this makes sense! We could ship it as part of v0.5.0 if you want?

@charliermarsh charliermarsh added this to the v0.5.0 milestone Jun 1, 2024
@MichaReiser MichaReiser modified the milestones: v0.5.0, v0.6 Jun 27, 2024
@MichaReiser MichaReiser modified the milestones: v0.6, v0.7 Aug 12, 2024
@AlexWaygood
Copy link
Member Author

We've now made this change in preview mode; we'll be stabilising it in Ruff 0.7. Thanks @calumy!

@AlexWaygood AlexWaygood modified the milestones: v0.7, v0.8 Oct 17, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
linter Related to the linter rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants