1. Pypy
  2. Untitled project
  3. pypy

Commits

Armin Rigo  committed 3e1a496

Python 2.6 compatibility

  • Participants
  • Parent commits 7341987
  • Branches release-2.2.x

Comments (0)

Files changed (5)

File rpython/annotator/bookkeeper.py

View file
  • Ignore whitespace
 from __future__ import absolute_import
 
 import sys, types, inspect, weakref
-from collections import OrderedDict
 
 from rpython.flowspace.model import Constant
 from rpython.annotator.model import (SomeOrderedDict,
                 for e in x:
                     listdef.generalize(self.immutablevalue(e, False))
                 result = SomeList(listdef)
-        elif tp is dict or tp is r_dict or tp is OrderedDict:
+        elif tp is dict or tp is r_dict or tp is SomeOrderedDict.knowntype:
             if need_const:
                 key = Constant(x)
                 try:
                     dictdef.generalize_key(self.immutablevalue(ek, False))
                     dictdef.generalize_value(self.immutablevalue(ev, False))
                     dictdef.seen_prebuilt_key(ek)
-                if tp is OrderedDict:
+                if tp is SomeOrderedDict.knowntype:
                     result = SomeOrderedDict(dictdef)
                 else:
                     result = SomeDict(dictdef)

File rpython/annotator/builtin.py

View file
  • Ignore whitespace
 Built-in functions.
 """
 import sys
-from collections import OrderedDict
 
 from rpython.annotator.model import (
     SomeInteger, SomeObject, SomeChar, SomeBool, SomeString, SomeTuple, s_Bool,
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.instantiate] = robjmodel_instantiate
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.r_dict] = robjmodel_r_dict
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.r_ordereddict] = robjmodel_r_ordereddict
-BUILTIN_ANALYZERS[OrderedDict] = lambda : SomeOrderedDict(getbookkeeper().getdictdef())
+BUILTIN_ANALYZERS[SomeOrderedDict.knowntype] = lambda : SomeOrderedDict(getbookkeeper().getdictdef())
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.hlinvoke] = robjmodel_hlinvoke
 BUILTIN_ANALYZERS[rpython.rlib.objectmodel.keepalive_until_here] = robjmodel_keepalive_until_here
 BUILTIN_ANALYZERS[rpython.rtyper.lltypesystem.llmemory.cast_ptr_to_adr] = llmemory_cast_ptr_to_adr

File rpython/annotator/model.py

View file
  • Ignore whitespace
 import inspect
 import weakref
 from types import BuiltinFunctionType, MethodType
-from collections import OrderedDict
 
 import rpython
 from rpython.tool import descriptor
             return '{...%s...}' % (len(const),)
 
 class SomeOrderedDict(SomeDict):
-    knowntype = OrderedDict
+    try:
+        from collections import OrderedDict as knowntype
+    except ImportError:    # Python 2.6
+        class PseudoOrderedDict(dict): pass
+        knowntype = PseudoOrderedDict
 
     def method_copy(dct):
         return SomeOrderedDict(dct.dictdef)

File rpython/rtyper/rbuiltin.py

View file
  • Ignore whitespace
-from collections import OrderedDict
 
 from rpython.annotator import model as annmodel
 from rpython.flowspace.model import Constant
 BUILTIN_TYPER[isinstance] = rtype_builtin_isinstance
 BUILTIN_TYPER[hasattr] = rtype_builtin_hasattr
 BUILTIN_TYPER[objectmodel.r_dict] = rtype_r_dict
-BUILTIN_TYPER[OrderedDict] = rtype_ordered_dict
+BUILTIN_TYPER[annmodel.SomeOrderedDict.knowntype] = rtype_ordered_dict
 BUILTIN_TYPER[objectmodel.r_ordereddict] = rtype_ordered_dict
 
 # _________________________________________________________________

File rpython/rtyper/test/test_rordereddict.py

View file
  • Ignore whitespace
 
 import py
-from collections import OrderedDict
+try:
+    from collections import OrderedDict
+except ImportError:     # Python 2.6
+    py.test.skip("requires collections.OrderedDict")
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rtyper.lltypesystem import rordereddict, rstr
 from rpython.rlib.rarithmetic import intmask