Skip to content

Remove dangerous default argument #4002

Closed
@pnijhara

Description

@pnijhara

Hi,
It is good not to use the default arguments while calling a function.

MCVE Code Sample

In file xarray/tests/test_conventions.py

# Your code here
329    @contextlib.contextmanager
330    def roundtrip(
331        self, data, save_kwargs={}, open_kwargs={}, allow_cleanup_failure=False332    ):
333        store = CFEncodedInMemoryStore()
334        data.dump_to_store(store, **save_kwargs)

Problem Description

Default arguments in Python are evaluated once when the function definition is executed. This means that the expression is evaluated only once when the function is defined and that the same value is used for each subsequent call. So if you are modifying the mutable default argument — a list, dict, etc., it will be modified for all future calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions