[pypy-commit] pypy builtin-module: The 'appleveldefs' is now not very useful any more, because we can

arigo noreply at buildbot.pypy.org
Sun Dec 4 13:24:41 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: builtin-module
Changeset: r50114:0daa576a26ef
Date: 2011-12-04 11:17 +0100
http://bitbucket.org/pypy/pypy/changeset/0daa576a26ef/

Log:	The 'appleveldefs' is now not very useful any more, because we can
	simply have the app-level part of the module in lib_pypy. Use this
	technique instead of hacking at the import for _bisect.

diff --git a/lib_pypy/_bisect.py b/lib_pypy/_bisect.py
--- a/lib_pypy/_bisect.py
+++ b/lib_pypy/_bisect.py
@@ -1,3 +1,28 @@
 # indirection needed; otherwise the built-in module "_bisect" shadows
 # any file _bisect.py that would be found in the user dirs
 from __builtin__bisect import *
+
+
+def insort_left(a, x, lo=0, hi=-1):
+    """Insert item x in list a, and keep it sorted assuming a is sorted.
+
+If x is already in a, insert it to the left of the leftmost x.
+
+Optional args lo (default 0) and hi (default len(a)) bound the
+slice of a to be searched."""
+    n = bisect_left(a, x, lo, hi)
+    a.insert(n, x)
+
+
+def insort_right(a, x, lo=0, hi=-1):
+    """Insert item x in list a, and keep it sorted assuming a is sorted.
+
+If x is already in a, insert it to the right of the rightmost x.
+
+Optional args lo (default 0) and hi (default len(a)) bound the
+slice of a to be searched."""
+    n = bisect_right(a, x, lo, hi)
+    a.insert(n, x)
+
+
+insort = insort_right
diff --git a/pypy/module/_bisect/__init__.py b/pypy/module/_bisect/__init__.py
--- a/pypy/module/_bisect/__init__.py
+++ b/pypy/module/_bisect/__init__.py
@@ -16,9 +16,6 @@
     applevel_name = '__builtin__bisect'
 
     appleveldefs = {
-        'insort':        'app_bisect.insort_right',
-        'insort_left':   'app_bisect.insort_left',
-        'insort_right':  'app_bisect.insort_right',
         }
 
     interpleveldefs = {
diff --git a/pypy/module/_bisect/app_bisect.py b/pypy/module/_bisect/app_bisect.py
deleted file mode 100644
--- a/pypy/module/_bisect/app_bisect.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from _bisect import bisect_left, bisect_right
-
-
-def insort_left(a, x, lo=0, hi=-1):
-    """Insert item x in list a, and keep it sorted assuming a is sorted.
-
-If x is already in a, insert it to the left of the leftmost x.
-
-Optional args lo (default 0) and hi (default len(a)) bound the
-slice of a to be searched."""
-    n = bisect_left(a, x, lo, hi)
-    a.insert(n, x)
-
-
-def insort_right(a, x, lo=0, hi=-1):
-    """Insert item x in list a, and keep it sorted assuming a is sorted.
-
-If x is already in a, insert it to the right of the rightmost x.
-
-Optional args lo (default 0) and hi (default len(a)) bound the
-slice of a to be searched."""
-    n = bisect_right(a, x, lo, hi)
-    a.insert(n, x)


More information about the pypy-commit mailing list