Skip to content

RuntimeError: Set changed size during iteration #92

@seddonym

Description

@seddonym

Certain methods return sets from the graph's internals, e.g.

  • find_modules_directly_imported_by

If the graph is mutated while iterating through these sets, this can can a RuntimeError, e.g.

for imported_module in graph.find_modules_directly_imported_by("foo"):
   graph.remove_import(importer="foo", imported=imported_module)

This can be mitigated by copying the set before iterating over it, e.g.

for imported_module in graph.find_modules_directly_imported_by("foo").copy():
   graph.remove_import(importer="foo", imported=imported_module)

But probably it would be better for the method to return a copy.

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