HomePhabricator

[lint] Find function calls in default arguments

Description

[lint] Find function calls in default arguments

Summary:
Replace the existing python mutable linter with a ruff check.

The new check is much more complete than the old one, is checks more than just lists, sets or dict literals. In particular, it also detects function calls whose result will be used as a default argument. In python, the function would be executed only once at function definition time, which in itself might be confusing, but then the returned mutable arg could be changed and affect future calls.

Fix the detected infractions by either:

  • making the arg optional and default to None, and defining it in the body of the function if None
  • making the arg non-optional if all callsites already specify it

This is a backport of core#30553

See core#30543 for a particularly nasty example of bug that this check should prevent.

Depends on D18906

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D18907

Details

Provenance
PiRKAuthored on Fri, Nov 7, 13:40
PiRKPushed on Mon, Nov 10, 15:27
Reviewer
Restricted Project
Differential Revision
D18907: [lint] Find function calls in default arguments
Parents
rABC2ccfed5a9b22: [lint] remove isort linter, enable isort in ruff
Branches
Unknown
Tags
Unknown