[pypy-commit] pypy py3.5: ssue #2501: Don't implement local.__init__, allow the other base classes have their own __init__.
amauryfa
pypy.commits at gmail.com
Sun Mar 19 15:37:54 EDT 2017
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.5
Changeset: r90755:30d5769bd07d
Date: 2017-03-19 21:35 +0200
http://bitbucket.org/pypy/pypy/changeset/30d5769bd07d/
Log: ssue #2501: Don't implement local.__init__, allow the other base
classes have their own __init__.
diff --git a/pypy/module/thread/os_local.py b/pypy/module/thread/os_local.py
--- a/pypy/module/thread/os_local.py
+++ b/pypy/module/thread/os_local.py
@@ -1,6 +1,7 @@
import weakref
from rpython.rlib import jit
from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import oefmt
from pypy.interpreter.executioncontext import ExecutionContext
from pypy.interpreter.typedef import (TypeDef, interp2app, GetSetProperty,
descr_get_dict)
@@ -75,18 +76,18 @@
return w_dict
def descr_local__new__(space, w_subtype, __args__):
+ if __args__.arguments_w or __args__.keywords:
+ w_parent_init, _ = space.lookup_in_type_where(w_subtype, '__init__')
+ if w_parent_init is space.w_object:
+ raise oefmt(space.w_TypeError,
+ "Initialization arguments are not supported")
local = space.allocate_instance(Local, w_subtype)
Local.__init__(local, space, __args__)
return local
- def descr_local__init__(self, space):
- # No arguments allowed
- pass
-
Local.typedef = TypeDef("thread._local",
__doc__ = "Thread-local data",
__new__ = interp2app(Local.descr_local__new__.im_func),
- __init__ = interp2app(Local.descr_local__init__),
__dict__ = GetSetProperty(descr_get_dict, cls=Local),
)
diff --git a/pypy/module/thread/test/test_local.py b/pypy/module/thread/test/test_local.py
--- a/pypy/module/thread/test/test_local.py
+++ b/pypy/module/thread/test/test_local.py
@@ -72,6 +72,19 @@
assert seen1 == [1, 2, 3, 4, 5]
assert tags == ['???']
+ def test_local_init2(self):
+ import thread
+
+ class A(object):
+ def __init__(self, n):
+ assert n == 42
+ self.n = n
+ class X(thread._local, A):
+ pass
+
+ x = X(42)
+ assert x.n == 42
+
def test_local_setdict(self):
import _thread
x = _thread._local()
More information about the pypy-commit
mailing list