]> granicus.if.org Git - python/commitdiff
tracemalloc: filter_traces() raises a TypeError if filters is not an iterable
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 10 Mar 2014 10:05:07 +0000 (11:05 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 10 Mar 2014 10:05:07 +0000 (11:05 +0100)
Lib/test/test_tracemalloc.py
Lib/tracemalloc.py

index d1e5aef5c8cbee555badb2ef3101a56718ee73b3..c953885fc59cbe2772c4650c53326e25a25a4749 100644 (file)
@@ -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)
index f117127339aa548549a5941710eaf51e004c083d..adedfc5fb44b571e2829a8b803c6625cda6eb784 100644 (file)
@@ -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 = []