Ronan Lamy avatar Ronan Lamy committed b4d30dd Merge

hg merge default

Comments (0)

Files changed (10)

lib-python/2.7/collections.py

 from keyword import iskeyword as _iskeyword
 import sys as _sys
 import heapq as _heapq
+from operator import itemgetter as _itemgetter
 from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
 
 try:
 
     # Execute the template string in a temporary namespace and
     # support tracing utilities by setting a value for frame.f_globals['__name__']
-    namespace = {'__name__': 'namedtuple_%s' % typename}
+    namespace = {'__name__': 'namedtuple_%s' % typename,
+                 'OrderedDict': OrderedDict}
     try:
         exec template in namespace
     except SyntaxError, e:

pypy/doc/coding-guide.rst

 for the next milestone, both from an E-Mail and from a
 web interface.
 
-.. _`development tracker`: https://codespeak.net/issue/pypy-dev/
+.. _`development tracker`: https://bugs.pypy.org/
 
 use your codespeak login or register
 ------------------------------------
 tracker. Else, you can `register with the tracker`_ easily.
 
 
-.. _`register with the tracker`: https://codespeak.net/issue/pypy-dev/user?@template=register
+.. _`register with the tracker`: https://bugs.pypy.org/user?@template=register
 .. _`roundup`: http://roundup.sourceforge.net/
 
 

pypy/doc/confrest.py

 from confrest_oldpy import Project, Page, relpath
 html = py.xml.html
 
-class PyPyPage(Page): 
+
+class PyPyPage(Page):
     googlefragment = """
 <script type="text/javascript">
 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
 pageTracker._trackPageview();
 } catch(err) {}</script>
 """
+
     def fill_menubar(self):
         self.menubar = html.div(
-            html.a("home", 
-                   href=self.get_doclink("index.html"), 
-                   class_="menu"), 
+            html.a("home",
+                   href=self.get_doclink("index.html"),
+                   class_="menu"),
             " ",
             html.a("blog", href="http://morepypy.blogspot.com", class_="menu"),
-            " ", 
+            " ",
             html.a("getting-started",
                    href=self.get_doclink("getting-started.html"),
-                   class_="menu"), 
+                   class_="menu"),
             " ",
             html.a("documentation", href=self.get_doclink("docindex.html"),
                    class_="menu"),
-            " ", 
+            " ",
             html.a("hg", href="https://bitbucket.org/pypy/pypy",
                    class_="menu"),
-            " ", 
+            " ",
             html.a("issues",
-                   href="https://codespeak.net/issue/pypy-dev/",
+                   href="https://bugs.pypy.org/",
                    class_="menu"),
             " ", id="menubar")
 
         return relpath(self.targetpath.strpath,
                        self.project.docpath.join(target).strpath)
 
-    def unicode(self, doctype=True): 
-        page = self._root.unicode() 
+    def unicode(self, doctype=True):
+        page = self._root.unicode()
         page = page.replace("</body>", self.googlefragment + "</body>")
-        if doctype: 
-            return self.doctype + page 
-        else: 
-            return page 
-        
+        if doctype:
+            return self.doctype + page
+        else:
+            return page
 
-class Project(Project): 
+
+class Project(Project):
     mydir = py.path.local(__file__).dirpath()
 
-    title = "PyPy" 
+    title = "PyPy"
     stylesheet = 'style.css'
-    encoding = 'latin1' 
+    encoding = 'latin1'
     prefix_title = "PyPy"
     logo = html.div(
         html.a(
-            html.img(alt="PyPy", id="pyimg", 
-                     src="http://codespeak.net/pypy/img/py-web1.png", 
+            html.img(alt="PyPy", id="pyimg",
+                     src="http://codespeak.net/pypy/img/py-web1.png",
                      height=110, width=149)))
-    Page = PyPyPage 
+    Page = PyPyPage

pypy/doc/getting-started.rst

 ==================================
-Getting Started 
+Getting Started
 ==================================
 
 .. contents::
 
-.. _howtopypy: 
+.. _howtopypy:
 
 What is PyPy ?
 ==============
 .. _`RPython translation toolchain`: translation.html
 .. _`more...`: architecture.html
 
-Just the facts 
-============== 
+Just the facts
+==============
 
 Download a pre-built PyPy
 -------------------------
 ``pypy/pypy`` and documentation files in ``pypy/pypy/doc``.
 We try to ensure that the tip is always stable, but it might
 occasionally be broken.  You may want to check out `our nightly tests:`_
-find a revision (12-chars alphanumeric string, e.g. "963e808156b3") 
+find a revision (12-chars alphanumeric string, e.g. "963e808156b3")
 that passed at least the
 ``{linux32}`` tests (corresponding to a ``+`` sign on the
 line ``success``) and then, in your cloned repository, switch to this revision
 Understanding PyPy's architecture
 ---------------------------------
 
-For in-depth information about architecture and coding documentation 
-head over to the `documentation section`_ where you'll find lots of 
-interesting information.  Additionally, in true hacker spirit, you 
-may just `start reading sources`_ . 
+For in-depth information about architecture and coding documentation
+head over to the `documentation section`_ where you'll find lots of
+interesting information.  Additionally, in true hacker spirit, you
+may just `start reading sources`_ .
 
 .. _`documentation section`: index.html#project-documentation
 .. _`start reading sources`: getting-started-dev.html#start-reading-sources
 
-Filing bugs or feature requests 
+Filing bugs or feature requests
 -------------------------------
 
 You may file `bug reports`_ on our issue tracker which is
-also accessible through the 'issues' top menu of 
-the PyPy website.  `Using the development tracker`_ has 
-more detailed information on specific features of the tracker. 
+also accessible through the 'issues' top menu of
+the PyPy website.  `Using the development tracker`_ has
+more detailed information on specific features of the tracker.
 
 .. _`Using the development tracker`: coding-guide.html#using-development-tracker
-.. _bug reports:            https://codespeak.net/issue/pypy-dev/
+.. _bug reports: https://bugs.pypy.org/
 
 
 .. include:: _ref.txt

pypy/interpreter/pytraceback.py

 from pypy.interpreter import baseobjspace
 from pypy.interpreter.error import OperationError
+
 from rpython.tool.error import offset2lineno
 
 
 
     def descr__reduce__(self, space):
         from pypy.interpreter.mixedmodule import MixedModule
-        w_mod    = space.getbuiltinmodule('_pickle_support')
-        mod      = space.interp_w(MixedModule, w_mod)
+        w_mod = space.getbuiltinmodule('_pickle_support')
+        mod = space.interp_w(MixedModule, w_mod)
         new_inst = mod.get('traceback_new')
-        w        = space.wrap
+        w = space.wrap
 
         tup_base = []
         tup_state = [
         self.lasti = space.int_w(w_lasti)
         self.next = space.interp_w(PyTraceback, w_next, can_be_None=True)
 
+
 def record_application_traceback(space, operror, frame, last_instruction):
     if frame.pycode.hidden_applevel:
         return
     tb = PyTraceback(space, frame, last_instruction, tb)
     operror.set_traceback(tb)
 
+
 def check_traceback(space, w_tb, msg):
     from pypy.interpreter.typedef import PyTraceback
     tb = space.interpclass_w(w_tb)
-    if tb is None or not space.is_true(space.isinstance(tb, 
+    if tb is None or not space.is_true(space.isinstance(tb,
             space.gettypeobject(PyTraceback.typedef))):
         raise OperationError(space.w_TypeError, space.wrap(msg))
     return tb

pypy/interpreter/typedef.py

-"""
+import py
 
-
-"""
-import py
-from pypy.interpreter.gateway import interp2app, BuiltinCode, unwrap_spec,\
-     WrappedDefault
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.baseobjspace import Wrappable, DescrMismatch
 from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.gateway import (interp2app, BuiltinCode, unwrap_spec,
+     WrappedDefault)
+
+from rpython.rlib.jit import promote
+from rpython.rlib.objectmodel import compute_identity_hash, specialize
 from rpython.tool.sourcetools import compile2, func_with_new_name
-from rpython.rlib.objectmodel import instantiate, compute_identity_hash, specialize
-from rpython.rlib.jit import promote
 
-class TypeDef:
+
+class TypeDef(object):
     def __init__(self, __name, __base=None, __total_ordering__=None, **rawdict):
         "NOT_RPYTHON: initialization-time only"
         self.name = __name
         self.weakrefable = '__weakref__' in rawdict
         self.doc = rawdict.pop('__doc__', None)
         for base in bases:
-            self.hasdict     |= base.hasdict
+            self.hasdict |= base.hasdict
             self.weakrefable |= base.weakrefable
         self.rawdict = {}
         self.acceptable_as_base_class = '__new__' in rawdict
         return unknown_objclass_getter, cls
     miniglobals = {}
     if isinstance(cls, str):
-        assert cls.startswith('<'),"pythontype typecheck should begin with <"
+        assert cls.startswith('<'), "pythontype typecheck should begin with <"
         cls_name = cls[1:]
         typeexpr = "space.w_%s" % cls_name
     else:
         else:
             try:
                 return self.fget(self, space, w_obj)
-            except DescrMismatch, e:
+            except DescrMismatch:
                 return w_obj.descr_call_mismatch(
                     space, '__getattribute__',
                     self.reqcls, Arguments(space, [w_obj,
                                  space.wrap("readonly attribute"))
         try:
             fset(self, space, w_obj, w_value)
-        except DescrMismatch, e:
+        except DescrMismatch:
             w_obj.descr_call_mismatch(
                 space, '__setattr__',
                 self.reqcls, Arguments(space, [w_obj,
                                  space.wrap("cannot delete attribute"))
         try:
             fdel(self, space, w_obj)
-        except DescrMismatch, e:
+        except DescrMismatch:
             w_obj.descr_call_mismatch(
                 space, '__delattr__',
                 self.reqcls, Arguments(space, [w_obj,
 class Member(Wrappable):
     """For slots."""
     _immutable_ = True
+
     def __init__(self, index, name, w_cls):
         self.index = index
         self.name = name
 from pypy.interpreter.pyframe import PyFrame
 from pypy.interpreter.pyopcode import SuspendedUnroller
 from pypy.interpreter.module import Module
-from pypy.interpreter.function import Function, Method, StaticMethod
-from pypy.interpreter.function import ClassMethod
-from pypy.interpreter.function import BuiltinFunction, descr_function_get
+from pypy.interpreter.function import (Function, Method, StaticMethod,
+    ClassMethod, BuiltinFunction, descr_function_get)
 from pypy.interpreter.pytraceback import PyTraceback
 from pypy.interpreter.generator import GeneratorIterator
 from pypy.interpreter.nestedscope import Cell
 def fget_co_flags(space, code): # unwrapping through unwrap_spec
     sig = code.signature()
     flags = 0
-    if sig.has_vararg(): flags |= CO_VARARGS
-    if sig.has_kwarg(): flags |= CO_VARKEYWORDS
+    if sig.has_vararg():
+        flags |= CO_VARARGS
+    if sig.has_kwarg():
+        flags |= CO_VARKEYWORDS
     return space.wrap(flags)
 
 def fget_co_consts(space, code): # unwrapping through unwrap_spec
     __eq__ = interp2app(PyCode.descr_code__eq__),
     __ne__ = descr_generic_ne,
     __hash__ = interp2app(PyCode.descr_code__hash__),
-    __reduce__   = interp2app(PyCode.descr__reduce__),
+    __reduce__ = interp2app(PyCode.descr__reduce__),
     __repr__ = interp2app(PyCode.repr),
     co_argcount = interp_attrproperty('co_argcount', cls=PyCode),
     co_nlocals = interp_attrproperty('co_nlocals', cls=PyCode),
     co_code = interp_attrproperty('co_code', cls=PyCode),
     co_consts = GetSetProperty(PyCode.fget_co_consts),
     co_names = GetSetProperty(PyCode.fget_co_names),
-    co_varnames =  GetSetProperty(PyCode.fget_co_varnames),
-    co_freevars =  GetSetProperty(PyCode.fget_co_freevars),
-    co_cellvars =  GetSetProperty(PyCode.fget_co_cellvars),
+    co_varnames = GetSetProperty(PyCode.fget_co_varnames),
+    co_freevars = GetSetProperty(PyCode.fget_co_freevars),
+    co_cellvars = GetSetProperty(PyCode.fget_co_cellvars),
     co_filename = interp_attrproperty('co_filename', cls=PyCode),
     co_name = interp_attrproperty('co_name', cls=PyCode),
     co_firstlineno = interp_attrproperty('co_firstlineno', cls=PyCode),
 PyCode.typedef.acceptable_as_base_class = False
 
 PyFrame.typedef = TypeDef('frame',
-    __reduce__   = interp2app(PyFrame.descr__reduce__),
+    __reduce__ = interp2app(PyFrame.descr__reduce__),
     __setstate__ = interp2app(PyFrame.descr__setstate__),
     f_builtins = GetSetProperty(PyFrame.fget_f_builtins),
     f_lineno = GetSetProperty(PyFrame.fget_f_lineno, PyFrame.fset_f_lineno),
     __new__ = interp2app(Method.descr_method__new__.im_func),
     __call__ = interp2app(Method.descr_method_call),
     __get__ = interp2app(Method.descr_method_get),
-    im_func  = interp_attrproperty_w('w_function', cls=Method),
+    im_func = interp_attrproperty_w('w_function', cls=Method),
     __func__ = interp_attrproperty_w('w_function', cls=Method),
-    im_self  = interp_attrproperty_w('w_instance', cls=Method),
+    im_self = interp_attrproperty_w('w_instance', cls=Method),
     __self__ = interp_attrproperty_w('w_instance', cls=Method),
     im_class = interp_attrproperty_w('w_class', cls=Method),
     __getattribute__ = interp2app(Method.descr_method_getattribute),
 
 def always_none(self, obj):
     return None
-BuiltinFunction.typedef = TypeDef("builtin_function",**Function.typedef.rawdict)
+BuiltinFunction.typedef = TypeDef("builtin_function", **Function.typedef.rawdict)
 BuiltinFunction.typedef.rawdict.update({
     '__new__': interp2app(BuiltinFunction.descr_builtinfunction__new__.im_func),
     '__self__': GetSetProperty(always_none, cls=BuiltinFunction),
 BuiltinFunction.typedef.acceptable_as_base_class = False
 
 PyTraceback.typedef = TypeDef("traceback",
-    __reduce__   = interp2app(PyTraceback.descr__reduce__),
+    __reduce__ = interp2app(PyTraceback.descr__reduce__),
     __setstate__ = interp2app(PyTraceback.descr__setstate__),
-    tb_frame  = interp_attrproperty('frame', cls=PyTraceback),
-    tb_lasti  = interp_attrproperty('lasti', cls=PyTraceback),
+    tb_frame = interp_attrproperty('frame', cls=PyTraceback),
+    tb_lasti = interp_attrproperty('lasti', cls=PyTraceback),
     tb_lineno = GetSetProperty(PyTraceback.descr_tb_lineno),
-    tb_next   = interp_attrproperty('next', cls=PyTraceback),
+    tb_next = interp_attrproperty('next', cls=PyTraceback),
     )
 PyTraceback.typedef.acceptable_as_base_class = False
 
 Cell.typedef.acceptable_as_base_class = False
 
 Ellipsis.typedef = TypeDef("Ellipsis",
-    __repr__   = interp2app(Ellipsis.descr__repr__),
+    __repr__ = interp2app(Ellipsis.descr__repr__),
 )
 Ellipsis.typedef.acceptable_as_base_class = False
 
 NotImplemented.typedef = TypeDef("NotImplemented",
-    __repr__   = interp2app(NotImplemented.descr__repr__),
+    __repr__ = interp2app(NotImplemented.descr__repr__),
 )
 NotImplemented.typedef.acceptable_as_base_class = False
 

pypy/objspace/std/tupleobject.py

     start, stop = normalize_simple_slice(space, length, w_start, w_stop)
     return space.newtuple(w_tuple.wrappeditems[start:stop])
 
+THRESHOLD = 7
+
+def unroll_tuple_contains(space, w_tuple, w_obj):
+    if (jit.isconstant(w_tuple) or jit.isvirtual(w_tuple) and
+        len(w_tuple.wrappeditems) < THRESHOLD):
+        return True
+    return False
+
+@jit.look_inside_iff(unroll_tuple_contains)
 def contains__Tuple_ANY(space, w_tuple, w_obj):
     for w_item in w_tuple.wrappeditems:
         if space.eq_w(w_item, w_obj):

pypy/objspace/std/typeobject.py

+from pypy.interpreter import gateway
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.function import Function, StaticMethod
+from pypy.interpreter.typedef import weakref_descr
 from pypy.objspace.std.model import W_Object
 from pypy.objspace.std.register_all import register_all
-from pypy.interpreter.function import Function, StaticMethod
-from pypy.interpreter import gateway
-from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.typedef import weakref_descr
-from pypy.interpreter.baseobjspace import W_Root
 from pypy.objspace.std.stdtypedef import std_dict_descr, issubtypedef, Member
-from pypy.objspace.std.objecttype import object_typedef
-from pypy.objspace.std import identitydict
-from rpython.rlib.objectmodel import we_are_translated
+
+from rpython.rlib.jit import (promote, elidable_promote, we_are_jitted,
+     promote_string, elidable, dont_look_inside, unroll_safe)
 from rpython.rlib.objectmodel import current_object_addr_as_int, compute_hash
-from rpython.rlib.jit import promote, elidable_promote, we_are_jitted,\
-     promote_string
-from rpython.rlib.jit import elidable, dont_look_inside, unroll_safe
 from rpython.rlib.rarithmetic import intmask, r_uint
 
+
 class TypeCell(W_Root):
     def __init__(self, w_value=None):
         self.w_value = w_value
 
+
 def unwrap_cell(space, w_value):
     if (space.config.objspace.std.withtypeversion and
             isinstance(w_value, TypeCell)):
             if attr in w_self.lazyloaders:
                 # very clever next line: it forces the attr string
                 # to be interned.
-                w_attr = space.new_interned_str(attr)
+                space.new_interned_str(attr)
                 loader = w_self.lazyloaders[attr]
                 del w_self.lazyloaders[attr]
                 w_value = loader()
 
     def get_module(w_self):
         space = w_self.space
-        if w_self.is_heaptype() and '__module__' in w_self.dict_w:
+        if w_self.is_heaptype() and w_self.getdictvalue(space, '__module__') is not None:
             return w_self.getdictvalue(space, '__module__')
         else:
             # for non-heap types, CPython checks for a module.name in the
             mod = '__builtin__'
         else:
             mod = space.str_w(w_mod)
-        if mod !='__builtin__':
+        if mod != '__builtin__':
             return '%s.%s' % (mod, w_self.name)
         else:
             return w_self.name
                 subclasses_w.append(w_ob)
         return subclasses_w
 
-
     # for now, weakref support for W_TypeObject is hard to get automatically
     _lifeline_ = None
+
     def getweakref(self):
         return self._lifeline_
+
     def setweakref(self, space, weakreflifeline):
         self._lifeline_ = weakreflifeline
+
     def delweakref(self):
         self._lifeline_ = None
 
             else:
                 create_slot(w_self, slot_name)
     wantdict = wantdict or hasoldstylebase
-    if wantdict: create_dict_slot(w_self)
-    if wantweakref: create_weakref_slot(w_self)
-    if '__del__' in dict_w: w_self.needsdel = True
+    if wantdict:
+        create_dict_slot(w_self)
+    if wantweakref:
+        create_weakref_slot(w_self)
+    if '__del__' in dict_w:
+        w_self.needsdel = True
 
 def create_slot(w_self, slot_name):
     space = w_self.space
         kind = 'type'
     else:
         kind = 'class'
-    if mod is not None and mod !='__builtin__':
+    if mod is not None and mod != '__builtin__':
         return space.wrap("<%s '%s.%s'>" % (kind, mod, w_obj.name))
     else:
         return space.wrap("<%s '%s'>" % (kind, w_obj.name))
         # __get__(None, type): turns e.g. functions into unbound methods
         return space.get(w_value, space.w_None, w_type)
     if w_descr is not None:
-        return space.get(w_descr,w_type)
+        return space.get(w_descr, w_type)
     raise operationerrfmt(space.w_AttributeError,
                           "type object '%s' has no attribute '%s'",
                           w_type.name, name)
             return mro_error(space, orderlists)  # no candidate found
         assert candidate not in order
         order.append(candidate)
-        for i in range(len(orderlists)-1, -1, -1):
+        for i in range(len(orderlists) - 1, -1, -1):
             if orderlists[i][0] is candidate:
                 del orderlists[i][0]
                 if len(orderlists[i]) == 0:

pypy/objspace/std/typetype.py

 from pypy.interpreter import gateway
-from pypy.interpreter.argument import Arguments
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.typedef import (GetSetProperty, descr_get_dict,
                                       weakref_descr)
     return space.wrap(w_type.name)
 
 def descr_set__name__(space, w_type, w_value):
-    w_type = _check(space, w_type)    
+    w_type = _check(space, w_type)
     if not w_type.is_heaptype():
-        raise operationerrfmt(space.w_TypeError, 
+        raise operationerrfmt(space.w_TypeError,
                               "can't set %s.__name__", w_type.name)
     w_type.name = space.str_w(w_value)
 
 
 def descr_set__bases__(space, w_type, w_value):
     # this assumes all app-level type objects are W_TypeObject
-    from pypy.objspace.std.typeobject import W_TypeObject
-    from pypy.objspace.std.typeobject import check_and_find_best_base
-    from pypy.objspace.std.typeobject import get_parent_layout
-    from pypy.objspace.std.typeobject import is_mro_purely_of_types
+    from pypy.objspace.std.typeobject import (W_TypeObject, get_parent_layout,
+        check_and_find_best_base, is_mro_purely_of_types)
+
     w_type = _check(space, w_type)
     if not w_type.is_heaptype():
         raise operationerrfmt(space.w_TypeError,
     #
     w_type = _check(space, w_type)
     flags = 0
-    if w_type.flag_heaptype: flags |= _HEAPTYPE
-    if w_type.flag_cpytype:  flags |= _CPYTYPE
-    if w_type.flag_abstract: flags |= _ABSTRACT
+    if w_type.flag_heaptype:
+        flags |= _HEAPTYPE
+    if w_type.flag_cpytype:
+        flags |= _CPYTYPE
+    if w_type.flag_abstract:
+        flags |= _ABSTRACT
     return space.wrap(flags)
 
 def descr_get__module(space, w_type):

rpython/flowspace/specialcase.py

 def sc_we_are_translated(space, we_are_translated, args_w):
     return Constant(True)
 
+def sc_locals(space, locals, args):
+    raise Exception(
+        "A function calling locals() is not RPython.  "
+        "Note that if you're translating code outside the PyPy "
+        "repository, a likely cause is that py.test's --assert=rewrite "
+        "mode is getting in the way.  You should copy the file "
+        "pytest.ini from the root of the PyPy repository into your "
+        "own project.")
+
 SPECIAL_CASES = {__import__: sc_import, r_uint: sc_r_uint,
-        we_are_translated: sc_we_are_translated}
+        we_are_translated: sc_we_are_translated,
+        locals: sc_locals}
 for fn in OperationName:
     SPECIAL_CASES[fn] = sc_operator
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.