summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-03-10 11:05:07 +0100
committerVictor Stinner <victor.stinner@gmail.com>2014-03-10 11:05:07 +0100
commit8431b42f67e661f123b1aa589a7a889740fca749 (patch)
tree58a189105d653b9b80bc7aae32c8a53ec13e7571 /Lib
parent7c1a1418cbbd7b1296fca91d4267a02b0fc83556 (diff)
downloadcpython-8431b42f67e661f123b1aa589a7a889740fca749.tar.gz
tracemalloc: filter_traces() raises a TypeError if filters is not an iterable
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_tracemalloc.py2
-rw-r--r--Lib/tracemalloc.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index d1e5aef5c8..c953885fc5 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -346,6 +346,8 @@ class TestSnapshot(unittest.TestCase):
self.assertIsNot(snapshot5.traces, snapshot.traces)
self.assertEqual(snapshot5.traces, snapshot.traces)
+ self.assertRaises(TypeError, snapshot.filter_traces, filter1)
+
def test_snapshot_group_by_line(self):
snapshot, snapshot2 = create_snapshots()
tb_0 = traceback_lineno('<unknown>', 0)
diff --git a/Lib/tracemalloc.py b/Lib/tracemalloc.py
index f117127339..adedfc5fb4 100644
--- a/Lib/tracemalloc.py
+++ b/Lib/tracemalloc.py
@@ -1,4 +1,4 @@
-from collections import Sequence
+from collections import Sequence, Iterable
from functools import total_ordering
import fnmatch
import linecache
@@ -382,6 +382,9 @@ class Snapshot:
is a list of Filter instances. If filters is an empty list, return a
new Snapshot instance with a copy of the traces.
"""
+ if not isinstance(filters, Iterable):
+ raise TypeError("filters must be a list of filters, not %s"
+ % type(filters).__name__)
if filters:
include_filters = []
exclude_filters = []