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

Ignore mutable-argument-default (B006) in .pyi stubs #14026

Closed
jorenham opened this issue Oct 31, 2024 · 1 comment · Fixed by #14058
Closed

Ignore mutable-argument-default (B006) in .pyi stubs #14026

jorenham opened this issue Oct 31, 2024 · 1 comment · Fixed by #14058
Labels
accepted Ready for implementation help wanted Contributions especially welcome rule Implementing or modifying a lint rule

Comments

@jorenham
Copy link

Mutable argument defaults can only be a problem at runtime. But at the moment, B006 will also be reported in .pyi stub files, even though it is certain that mutations can never occur there.

For example, consider the following function in scipy-stubs/stats/_mstats_basic.pyi:578:

def mquantiles(
    a: _ArrayLikeFloat_co,
    prob: _ArrayLikeFloat_co = [0.25, 0.5, 0.75],
    alphap: AnyReal = 0.4,
    betap: AnyReal = 0.4,
    axis: CanIndex | None = None,
    limit: tuple[AnyReal, AnyReal] | tuple[()] = (),
) -> _MArrayND: ...

For the prob parameter the following error is reported:

scipy-stubs/stats/_mstats_basic.pyi:580:32: B006 Do not use mutable data structures for argument defaults

I think that "mutable" defaults should be allowed in cases like these. Having explicit parameter defaults that match the runtime can be seen as a form of documentation. This is especially useful when the runtime sources aren't available, which is quite common in this scipy-stubs case.

@AlexWaygood
Copy link
Member

Yeah, your argument makes sense. You want to emulate the runtime in a stub file; whether or not the runtime should be using mutable defaults or not, you'll want to accurately represent that in the stub.

@AlexWaygood AlexWaygood added help wanted Contributions especially welcome accepted Ready for implementation labels Oct 31, 2024
@AlexWaygood AlexWaygood changed the title mutable-argument-default (B006) in .pyi stubs Ignore mutable-argument-default (B006) in .pyi stubs Oct 31, 2024
@dhruvmanila dhruvmanila added the rule Implementing or modifying a lint rule label Nov 1, 2024
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

Successfully merging a pull request may close this issue.

3 participants