Skip to content

Refactor Cell.__getstate__ to use modern super() implementation #3084

@falloficarus22

Description

@falloficarus22

Description

The Cell class in mesa/discrete_space/cell.py currently uses a manual implementation for getstate to handle serialization (pickling). It intentionally clears the connections attribute to avoid infinite recursion during deepcopy operations.

The code currently contains a FIXME indicating this logic was a temporary workaround for older Python versions:

# fixme, once we shift to 3.11, replace this with super. __getstate__

Context

The project's pyproject.toml now sets requires-python = ">=3.12", meaning the legacy workaround is no longer necessary.

Task

Refactor the getstate method in mesa/discrete_space/cell.py to:

  1. Remove the manual dictionary construction.
  2. Utilize super().__getstate__() to retrieve the default state.
  3. Ensure the logic that clears the connections dictionary is preserved to prevent recursion errors.

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