-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
acceptedReady for implementationReady for implementationhelp wantedContributions especially welcomeContributions especially welcomeruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acceptedReady for implementationReady for implementationhelp wantedContributions especially welcomeContributions especially welcomeruleImplementing or modifying a lint ruleImplementing or modifying a lint rule