Skip to content

Commit 8ce8ff9

Browse files
committed
tracemalloc: filter_traces() raises a TypeError if filters is not an iterable
1 parent bcfcfc5 commit 8ce8ff9

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/test/test_tracemalloc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ def test_filter_traces(self):
346346
self.assertIsNot(snapshot5.traces, snapshot.traces)
347347
self.assertEqual(snapshot5.traces, snapshot.traces)
348348

349+
self.assertRaises(TypeError, snapshot.filter_traces, filter1)
350+
349351
def test_snapshot_group_by_line(self):
350352
snapshot, snapshot2 = create_snapshots()
351353
tb_0 = traceback_lineno('<unknown>', 0)

Lib/tracemalloc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import Sequence
1+
from collections import Sequence, Iterable
22
from functools import total_ordering
33
import fnmatch
44
import linecache
@@ -382,6 +382,9 @@ def filter_traces(self, filters):
382382
is a list of Filter instances. If filters is an empty list, return a
383383
new Snapshot instance with a copy of the traces.
384384
"""
385+
if not isinstance(filters, Iterable):
386+
raise TypeError("filters must be a list of filters, not %s"
387+
% type(filters).__name__)
385388
if filters:
386389
include_filters = []
387390
exclude_filters = []

0 commit comments

Comments
 (0)