Skip to content

tracemalloc: _compare_grouped_stats mutates old_group, and a typo in _group_by #158234

Description

@Tony123-tech

Two small issues in Lib/tracemalloc.py:

  1. _compare_grouped_stats() mutates its old_group argument by popping
    keys from it. After the call, old_group is missing every key that
    was also in new_group.

  2. A typo in the error message raised by _group_by():
    "cumulative mode cannot by used" should be
    "cumulative mode cannot be used".

Reproduction for (1):

from tracemalloc import Statistic, _compare_grouped_stats
old = {"a": Statistic("a", 100, 2), "b": Statistic("b", 50, 1)}
new = {"a": Statistic("a", 200, 3), "c": Statistic("c", 10, 1)}
old_copy = dict(old)
_compare_grouped_stats(old, new)
print(len(old), len(old_copy))   # 1 2

Linked PRs

Activity

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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions