[pypy-commit] pypy default: Change __pypy__.list_strategy to raise a TypeError on non-list arguments

alex_gaynor noreply at buildbot.pypy.org
Thu Dec 1 14:14:30 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r50036:4eefaeec6777
Date: 2011-12-01 08:14 -0500
http://bitbucket.org/pypy/pypy/changeset/4eefaeec6777/

Log:	Change __pypy__.list_strategy to raise a TypeError on non-list
	arguments

diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -75,7 +75,7 @@
 
 def list_strategy(space, w_list):
     from pypy.objspace.std.listobject import W_ListObject
-    str_type = None
     if isinstance(w_list, W_ListObject):
-        str_type = w_list.strategy._applevel_repr
-    return space.wrap(str_type)
+        return space.wrap(w_list.strategy._applevel_repr)
+    else:
+        raise OperationError(space.w_TypeError, space.wrap("Can only get the list strategy of a list"))
diff --git a/pypy/module/__pypy__/test/test_special.py b/pypy/module/__pypy__/test/test_special.py
--- a/pypy/module/__pypy__/test/test_special.py
+++ b/pypy/module/__pypy__/test/test_special.py
@@ -57,17 +57,18 @@
 
     def test_list_strategy(self):
         from __pypy__ import list_strategy
-        l = [1,2,3]
+
+        l = [1, 2, 3]
         assert list_strategy(l) == "int"
-        l = ["a","b","c"]
+        l = ["a", "b", "c"]
         assert list_strategy(l) == "str"
-        l = [1.1,2.2,3.3]
+        l = [1.1, 2.2, 3.3]
         assert list_strategy(l) == "float"
         l = range(3)
         assert list_strategy(l) == "range"
-        l = [1,"b",3]
+        l = [1, "b", 3]
         assert list_strategy(l) == "object"
         l = []
         assert list_strategy(l) == "empty"
         o = 5
-        assert list_strategy(o) == None
+        raises(TypeError, list_strategy, 5)


More information about the pypy-commit mailing list