Author: Martin Matusiak <numero...@gmail.com> Branch: py3.3 Changeset: r72495:61fd7b56f3ed Date: 2014-07-26 12:41 +0200 http://bitbucket.org/pypy/pypy/changeset/61fd7b56f3ed/
Log: Merged pypy/pypy/py3.3 into py3.3 diff --git a/pypy/module/__builtin__/app_inspect.py b/pypy/module/__builtin__/app_inspect.py --- a/pypy/module/__builtin__/app_inspect.py +++ b/pypy/module/__builtin__/app_inspect.py @@ -53,8 +53,7 @@ if dir_meth is not None: result = dir_meth() if not isinstance(result, list): - raise TypeError("__dir__() must return a list, not %r" % ( - type(result),)) + result = list(result) # Will throw TypeError if not iterable result.sort() return result elif isinstance(obj, types.ModuleType): diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -482,7 +482,7 @@ def descr_hash(self, space): if space.eq_w(self.w_length, space.wrap(0)): w_tup = space.newtuple([self.w_length, space.w_None, space.w_None]) - elif space.eq_w(self.w_length, space.wrap(0)): + elif space.eq_w(self.w_length, space.wrap(1)): w_tup = space.newtuple([self.w_length, self.w_start, space.w_None]) else: w_tup = space.newtuple([self.w_length, self.w_start, self.w_step]) diff --git a/pypy/module/__builtin__/test/test_construct_singletons.py b/pypy/module/__builtin__/test/test_construct_singletons.py new file mode 100644 --- /dev/null +++ b/pypy/module/__builtin__/test/test_construct_singletons.py @@ -0,0 +1,7 @@ +class AppTestConstructSingletons: + + def test_construct_singletons(self): + none_type = type(None) + assert none_type() is None + raises(TypeError, none_type, 1, 2) + raises(TypeError, none_type, a=1, b=2) diff --git a/pypy/module/__builtin__/test/test_dir.py b/pypy/module/__builtin__/test/test_dir.py new file mode 100644 --- /dev/null +++ b/pypy/module/__builtin__/test/test_dir.py @@ -0,0 +1,26 @@ +class AppTestDir: + + def test_dir_obj__dir__tuple(self): + """If __dir__ method returns a tuple, cpython3 converts it to list.""" + class Foo(object): + def __dir__(self): + return ("b", "c", "a") + res = dir(Foo()) + assert isinstance(res, list) + assert res == ["a", "b", "c"] + + def test_dir_obj__dir__genexp(self): + """Generator expression is also converted to list by cpython3.""" + class Foo(object): + def __dir__(self): + return (i for i in ["b", "c", "a"]) + res = dir(Foo()) + assert isinstance(res, list) + assert res == ["a", "b", "c"] + + def test_dir_obj__dir__noniter(self): + """If result of __dir__ is not iterable, it's an error.""" + class Foo(object): + def __dir__(self): + return 42 + raises(TypeError, dir, Foo()) diff --git a/pypy/module/__builtin__/test/test_functional.py b/pypy/module/__builtin__/test/test_functional.py --- a/pypy/module/__builtin__/test/test_functional.py +++ b/pypy/module/__builtin__/test/test_functional.py @@ -484,7 +484,7 @@ for a in test_ranges: for b in test_ranges: if a == b: - assert (hash(a), hash(b)) + assert hash(a) == hash(b) # Ranges are unequal to other types (even sequence types) assert (range(0) == ()) is False diff --git a/pypy/module/math/__init__.py b/pypy/module/math/__init__.py --- a/pypy/module/math/__init__.py +++ b/pypy/module/math/__init__.py @@ -23,6 +23,7 @@ 'frexp' : 'interp_math.frexp', 'degrees' : 'interp_math.degrees', 'log' : 'interp_math.log', + 'log2' : 'interp_math.log2', 'log10' : 'interp_math.log10', 'fmod' : 'interp_math.fmod', 'atan' : 'interp_math.atan', diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py --- a/pypy/module/math/interp_math.py +++ b/pypy/module/math/interp_math.py @@ -228,6 +228,11 @@ return math1(space, math.log, w_base) return _log_any(space, w_x, base) +def log2(space, w_x): + """log2(x) -> the base 2 logarithm of x. + """ + return _log_any(space, w_x, 2.0) + def log10(space, w_x): """log10(x) -> the base 10 logarithm of x. """ diff --git a/pypy/module/math/test/test_math.py b/pypy/module/math/test/test_math.py --- a/pypy/module/math/test/test_math.py +++ b/pypy/module/math/test/test_math.py @@ -148,6 +148,19 @@ raises(ValueError, math.log1p, -1) raises(ValueError, math.log1p, -100) + def test_log2(self): + import math + self.ftest(math.log2(0.125), -3) + self.ftest(math.log2(0.5), -1) + self.ftest(math.log2(4), 2) + + def test_log10(self): + import math + self.ftest(math.log10(0.1), -1) + self.ftest(math.log10(10), 1) + self.ftest(math.log10(100), 2) + self.ftest(math.log10(0.01), -2) + def test_acosh(self): import math self.ftest(math.acosh(1), 0) diff --git a/pypy/objspace/std/nonetype.py b/pypy/objspace/std/nonetype.py --- a/pypy/objspace/std/nonetype.py +++ b/pypy/objspace/std/nonetype.py @@ -1,8 +1,15 @@ from pypy.objspace.std.stdtypedef import StdTypeDef +from pypy.interpreter import gateway +def descr__new__(space, w_type): + return space.w_None + # ____________________________________________________________ none_typedef = StdTypeDef("NoneType", + __new__ = gateway.interp2app(descr__new__) ) none_typedef.acceptable_as_base_class = False + + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit