Skip to content

Make E741 not apply to stub files #10569

@AlexWaygood

Description

@AlexWaygood

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    linterRelated to the linterruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions