[pypy-commit] pypy default: merge
fijal
pypy.commits at gmail.com
Fri Apr 1 06:05:05 EDT 2016
Author: fijal
Branch:
Changeset: r83487:325494587c00
Date: 2016-04-01 12:04 +0200
http://bitbucket.org/pypy/pypy/changeset/325494587c00/
Log: merge
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
@@ -172,7 +172,7 @@
def _promote(space, w_obj):
""" Promote the first argument of the function and return it. Promote is by
value for ints, floats, strs, unicodes (but not subclasses thereof) and by
- reference otherwise.
+ reference otherwise. (Unicodes not supported right now.)
This function is experimental!"""
from rpython.rlib import jit
@@ -181,7 +181,7 @@
elif space.is_w(space.type(w_obj), space.w_float):
jit.promote(space.float_w(w_obj))
elif space.is_w(space.type(w_obj), space.w_str):
- jit.promote_string(space.unicode_w(w_obj))
+ jit.promote_string(space.str_w(w_obj))
elif space.is_w(space.type(w_obj), space.w_unicode):
raise OperationError(space.w_TypeError, space.wrap(
"promoting unicode unsupported"))
diff --git a/pypy/module/operator/app_operator.py b/pypy/module/operator/app_operator.py
--- a/pypy/module/operator/app_operator.py
+++ b/pypy/module/operator/app_operator.py
@@ -79,54 +79,45 @@
else:
return _resolve_attr_chain(chain, obj, idx + 1)
-
-class _simple_attrgetter(object):
- def __init__(self, attr):
- self._attr = attr
+class attrgetter(object):
+ def __init__(self, attr, *attrs):
+ if (
+ not isinstance(attr, basestring) or
+ not all(isinstance(a, basestring) for a in attrs)
+ ):
+ def _raise_typeerror(obj):
+ raise TypeError(
+ "argument must be a string, not %r" % type(attr).__name__
+ )
+ self._call = _raise_typeerror
+ elif attrs:
+ self._multi_attrs = [
+ a.split(".") for a in [attr] + list(attrs)
+ ]
+ self._call = self._multi_attrgetter
+ elif "." not in attr:
+ self._simple_attr = attr
+ self._call = self._simple_attrgetter
+ else:
+ self._single_attr = attr.split(".")
+ self._call = self._single_attrgetter
def __call__(self, obj):
- return getattr(obj, self._attr)
+ return self._call(obj)
+ def _simple_attrgetter(self, obj):
+ return getattr(obj, self._simple_attr)
-class _single_attrgetter(object):
- def __init__(self, attrs):
- self._attrs = attrs
+ def _single_attrgetter(self, obj):
+ return _resolve_attr_chain(self._single_attr, obj)
- def __call__(self, obj):
- return _resolve_attr_chain(self._attrs, obj)
-
-
-class _multi_attrgetter(object):
- def __init__(self, attrs):
- self._attrs = attrs
-
- def __call__(self, obj):
+ def _multi_attrgetter(self, obj):
return tuple([
_resolve_attr_chain(attrs, obj)
- for attrs in self._attrs
+ for attrs in self._multi_attrs
])
-def attrgetter(attr, *attrs):
- if (
- not isinstance(attr, basestring) or
- not all(isinstance(a, basestring) for a in attrs)
- ):
- def _raise_typeerror(obj):
- raise TypeError(
- "argument must be a string, not %r" % type(attr).__name__
- )
- return _raise_typeerror
- if attrs:
- return _multi_attrgetter([
- a.split(".") for a in [attr] + list(attrs)
- ])
- elif "." not in attr:
- return _simple_attrgetter(attr)
- else:
- return _single_attrgetter(attr.split("."))
-
-
class itemgetter(object):
def __init__(self, item, *items):
self._single = not bool(items)
diff --git a/pypy/module/operator/test/test_operator.py b/pypy/module/operator/test/test_operator.py
--- a/pypy/module/operator/test/test_operator.py
+++ b/pypy/module/operator/test/test_operator.py
@@ -47,7 +47,13 @@
a.name = "hello"
a.child = A()
a.child.name = "world"
+ a.child.foo = "bar"
assert attrgetter("child.name")(a) == "world"
+ assert attrgetter("child.name", "child.foo")(a) == ("world", "bar")
+
+ def test_attrgetter_type(self):
+ from operator import attrgetter
+ assert type(attrgetter("child.name")) is attrgetter
def test_concat(self):
class Seq1:
diff --git a/rpython/jit/metainterp/opencoder.py b/rpython/jit/metainterp/opencoder.py
--- a/rpython/jit/metainterp/opencoder.py
+++ b/rpython/jit/metainterp/opencoder.py
@@ -279,7 +279,6 @@
self._bigints = []
self._bigints_dict = {}
self._floats = []
- self._floats_dict = {}
self._snapshots = []
for i, inparg in enumerate(inputargs):
inparg.set_position(i)
@@ -305,7 +304,6 @@
self._bigints_dict = {}
self._refs_dict = llhelper.new_ref_dict_3()
- self._floats_dict = {}
debug_start("jit-trace-done")
debug_print("trace length: " + str(self._pos))
debug_print(" total snapshots: " + str(self._total_snapshots))
More information about the pypy-commit
mailing list