[pypy-commit] pypy py3k: intern() is now in the sys module

amauryfa noreply at buildbot.pypy.org
Sat Jan 14 21:48:40 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r51329:cb7edd67143d
Date: 2011-12-27 17:41 +0100
http://bitbucket.org/pypy/pypy/changeset/cb7edd67143d/

Log:	intern() is now in the sys module

diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py
--- a/pypy/module/__builtin__/__init__.py
+++ b/pypy/module/__builtin__/__init__.py
@@ -70,7 +70,6 @@
         'iter'          : 'operation.iter',
         'next'          : 'operation.next',
         'id'            : 'operation.id',
-        'intern'        : 'operation.intern',
         'callable'      : 'operation.callable',
 
         'compile'       : 'compiling.compile',
diff --git a/pypy/module/__builtin__/operation.py b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -220,15 +220,6 @@
     space.setattr(w_object, w_name, w_val)
     return space.w_None
 
-def intern(space, w_str):
-    """``Intern'' the given string.  This enters the string in the (global)
-table of interned strings whose purpose is to speed up dictionary lookups.
-Return the string itself or the previously interned string object with the
-same value."""
-    if space.is_w(space.type(w_str), space.w_unicode):
-        return space.new_interned_w_str(w_str)
-    raise OperationError(space.w_TypeError, space.wrap("intern() argument must be string."))
-
 def callable(space, w_object):
     """Check whether the object appears to be callable (i.e., some kind of
 function).  Note that classes are callable."""
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -93,20 +93,6 @@
         raises(ValueError, chr, -1)
         raises(ValueError, chr, sys.maxunicode+1)
 
-    def test_intern(self):
-        raises(TypeError, intern)
-        raises(TypeError, intern, 1)
-        class S(str):
-            pass
-        raises(TypeError, intern, S("hello"))
-        s = "never interned before"
-        s2 = intern(s)
-        assert s == s2
-        s3 = s.swapcase()
-        assert s3 != s2
-        s4 = s3.swapcase()
-        assert intern(s4) is s2
-
     def test_globals(self):
         d = {"foo":"bar"}
         exec("def f(): return globals()", d)
diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -55,6 +55,7 @@
         'getprofile'            : 'vm.getprofile',
         'call_tracing'          : 'vm.call_tracing',
         'getsizeof'             : 'vm.getsizeof',
+        'intern'                : 'vm.intern',
         
         'executable'            : 'space.wrap("py.py")', 
         'api_version'           : 'version.get_api_version(space)',
diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -607,3 +607,19 @@
         assert len(frames) == 1
         _, other_frame = frames.popitem()
         assert other_frame.f_code.co_name in ('other_thread', '?')
+
+    def test_intern(self):
+        from sys import intern
+        raises(TypeError, intern)
+        raises(TypeError, intern, 1)
+        class S(str):
+            pass
+        raises(TypeError, intern, S("hello"))
+        s = "never interned before"
+        s2 = intern(s)
+        assert s == s2
+        s3 = s.swapcase()
+        assert s3 != s2
+        s4 = s3.swapcase()
+        assert intern(s4) is s2
+
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -201,3 +201,13 @@
         raise OperationError(space.w_TypeError,
             space.wrap("sys.getsizeof() not implemented on PyPy"))
     return w_default
+
+def intern(space, w_str):
+    """``Intern'' the given string.  This enters the string in the (global)
+table of interned strings whose purpose is to speed up dictionary lookups.
+Return the string itself or the previously interned string object with the
+same value."""
+    if space.is_w(space.type(w_str), space.w_unicode):
+        return space.new_interned_w_str(w_str)
+    raise OperationError(space.w_TypeError, space.wrap("intern() argument must be string."))
+


More information about the pypy-commit mailing list