Skip to content

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

@jorenham

Description

@jorenham

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationhelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions