Author: Philip Jenvey <[email protected]>
Branch: py3k-refactor-str-types
Changeset: r68916:3e72e557a27b
Date: 2014-01-24 11:53 -0800
http://bitbucket.org/pypy/pypy/changeset/3e72e557a27b/
Log: try to avoid at least some cases of interp2app identifer name
clashes (grafted from 2f88f3eea121783eea13bf2d0d053eafc96e01a0)
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -750,6 +750,8 @@
argument.
"""
flatten = {}
+ caller = sys._getframe(1)
+ caller_name = caller.f_globals.get('__name__')
for base in inspect.getmro(M):
if base is object:
continue
@@ -764,13 +766,17 @@
elif isinstance(value, staticmethod):
func = value.__get__(42)
func = func_with_new_name(func, func.__name__)
+ if caller_name:
+ # staticmethods lack a unique im_class so further
+ # distinguish them from themselves
+ func.__module__ = caller_name
value = staticmethod(func)
elif isinstance(value, classmethod):
raise AssertionError("classmethods not supported "
"in 'import_from_mixin'")
flatten[key] = value
#
- target = sys._getframe(1).f_locals
+ target = caller.f_locals
for key, value in flatten.items():
if key in target:
raise Exception("import_from_mixin: would overwrite the value "
diff --git a/rpython/rlib/test/test_objectmodel.py
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -621,3 +621,14 @@
class B(A):
import_from_mixin(M)
assert B().foo == 42
+
+ d = dict(__name__='foo')
+ exec """class M(object):
+ @staticmethod
+ def f(): pass
+ """ in d
+ M = d['M']
+ class A(object):
+ import_from_mixin(M)
+ assert A.f is not M.f
+ assert A.f.__module__ != M.f.__module__
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit