Parsl / parsl

Parsl - a Python parallel scripting library

Home Page:http://parsl-project.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

linter could detect suspiciously mutable default values in function definitions

benclifford opened this issue · comments

Is your feature request related to a problem? Please describe.

This is a developer oriented feature request.

In Python code, definitions with mutable default values like this list:

def f(l=[]):
    ...

are suspicious, because there is the possibility for f to mutate l and affect subsequent invocations.

It would be nice if this sort of stuff was detected...

Describe the solution you'd like

One way would be linting to only allow a specific set of known-good types as default values.

This could be either the types of the values themselves, or the annotated types (for example, []: Sequence, would be safe in the presence of strong type-checking, because a Sequence cannot be mutated)

Describe alternatives you've considered
null action of allowing this to continue reoccuring and hoping people notice.

Additional context
related to mypy-style type checking

looks like flake8-bugbear rule B006 would catch this -- (thanks fediverse: https://mastodon.hawaga.org.uk/web/@benc/110740310264465283 )

see PR #2832 for working on flake8-bugbear for this