Skip to content

CellCollection.cells exposes a mutable cached list, causing inconsistent collection behavior #4142

Closed

Description

@sangitabera

Describe the bug
The CellCollection.cells property uses @cached_property and returns a mutable list of the collection's cells.

Because the list is cached, modifying the returned list affects subsequent accesses to collection.cells, even though the underlying collection (_cells) remains unchanged.

Expected behavior
Modifying the list returned by collection.cells should not modify the result of subsequent accesses or affect operations on the collection.

To Reproduce

cell1 = Cell((0, 0))
cell2 = Cell((0, 1))

collection = CellCollection([cell1, cell2])

cells = collection.cells
cells.clear()

print(len(collection))         # 2
print(len(collection.cells))   # 0

Activity

  1. added
    bug
    on Nov 19, 2026
  2. quaquel commented on Nov 20, 2026

    @quaquel
    Member

    Look at the docstring for CellCollection: "An immutable collection of cells". So, I don't see a bug here.

  3. quaquel commented on Nov 20, 2026

    @quaquel
    Member

    I think I begin to understand the claimed bug. Closing it might be premature. However, the proper fix would be to to let the property return a tuple rather than a list. Since this is a bug fix, the fact that it might be break stuff does not matter for semver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions