From addb5a6a75e926deadf1a80209ce39de0d9ca940 Mon Sep 17 00:00:00 2001 From: Wilfried Luebbe Date: Sat, 22 Mar 2014 16:48:21 +0100 Subject: [PATCH] changed to new method attribute names (im_func -> __func__) 5 .py modules were changed by the 2to3 tool (one was imcomplete as it had a hasattr() function) 2 .pyx were changed manually 1 additional .py module had im_func in a doc-test --- src/sage/categories/sets_cat.py | 2 +- src/sage/combinat/sf/k_dual.py | 6 +++--- src/sage/combinat/sf/new_kschur.py | 24 ++++++++++++------------ src/sage/misc/fpickle.pyx | 22 +++++++++++----------- src/sage/misc/function_mangling.pyx | 2 +- src/sage/misc/sageinspect.py | 4 ++-- src/sage/sets/set_from_iterator.py | 8 ++++---- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/sage/categories/sets_cat.py b/src/sage/categories/sets_cat.py index 989e4026a4c..5c8ea4ae078 100644 --- a/src/sage/categories/sets_cat.py +++ b/src/sage/categories/sets_cat.py @@ -604,7 +604,7 @@ def _test_elements_eq_transitive(self, **options): We test a non transitive equality:: sage: R = Zp(3) - sage: Sets().ParentMethods._test_elements_eq_transitive.im_func(R,elements=[R(3,2),R(3,1),R(0)]) + sage: Sets().ParentMethods._test_elements_eq_transitive.__func__(R,elements=[R(3,2),R(3,1),R(0)]) Traceback (most recent call last): ... AssertionError: non transitive equality: diff --git a/src/sage/combinat/sf/k_dual.py b/src/sage/combinat/sf/k_dual.py index 0ddac1f8933..43991509f31 100644 --- a/src/sage/combinat/sf/k_dual.py +++ b/src/sage/combinat/sf/k_dual.py @@ -912,9 +912,9 @@ def __init__(self, kBoundedRing, prefix): # The following are meant to be inherited with the category framework, but # this fails because they are methods of Parent. The trick below overcomes # this problem. - __getitem__ = KBoundedQuotientBases.ParentMethods.__getitem__.im_func - _repr_term = KBoundedQuotientBases.ParentMethods._repr_term.im_func - _element_constructor_ = KBoundedQuotientBases.ParentMethods._element_constructor_.im_func + __getitem__ = KBoundedQuotientBases.ParentMethods.__getitem__.__func__ + _repr_term = KBoundedQuotientBases.ParentMethods._repr_term.__func__ + _element_constructor_ = KBoundedQuotientBases.ParentMethods._element_constructor_.__func__ _element_constructor = _element_constructor_ class kMonomial(KBoundedQuotientBasis): diff --git a/src/sage/combinat/sf/new_kschur.py b/src/sage/combinat/sf/new_kschur.py index ebe979b7a4a..b28dadec253 100644 --- a/src/sage/combinat/sf/new_kschur.py +++ b/src/sage/combinat/sf/new_kschur.py @@ -580,7 +580,7 @@ def counit(self, element): class ElementMethods: - __mul__ = Magmas.ElementMethods.__mul__.im_func + __mul__ = Magmas.ElementMethods.__mul__.__func__ def _mul_(self, other): r""" @@ -1002,10 +1002,10 @@ def __init__(self, kBoundedRing): # The following are meant to be inherited with the category framework, but # this fails because they are methods of Parent. The trick below overcomes # this problem. - __getitem__ = KBoundedSubspaceBases.ParentMethods.__getitem__.im_func - _repr_term = KBoundedSubspaceBases.ParentMethods._repr_term.im_func - _convert_map_from_ = KBoundedSubspaceBases.ParentMethods._convert_map_from_.im_func - _element_constructor_ = KBoundedSubspaceBases.ParentMethods._element_constructor_.im_func + __getitem__ = KBoundedSubspaceBases.ParentMethods.__getitem__.__func__ + _repr_term = KBoundedSubspaceBases.ParentMethods._repr_term.__func__ + _convert_map_from_ = KBoundedSubspaceBases.ParentMethods._convert_map_from_.__func__ + _element_constructor_ = KBoundedSubspaceBases.ParentMethods._element_constructor_.__func__ _element_constructor = _element_constructor_ def _repr_(self): @@ -1221,11 +1221,11 @@ def __init__(self, kBoundedRing): # The following are meant to be inherited with the category framework, but # this fails because they are methods of Parent. The trick below overcomes # this problem. - __getitem__ = KBoundedSubspaceBases.ParentMethods.__getitem__.im_func - _repr_term = KBoundedSubspaceBases.ParentMethods._repr_term.im_func + __getitem__ = KBoundedSubspaceBases.ParentMethods.__getitem__.__func__ + _repr_term = KBoundedSubspaceBases.ParentMethods._repr_term.__func__ _convert_map_from_ =\ - KBoundedSubspaceBases.ParentMethods._convert_map_from_.im_func - _element_constructor_ = KBoundedSubspaceBases.ParentMethods._element_constructor_.im_func + KBoundedSubspaceBases.ParentMethods._convert_map_from_.__func__ + _element_constructor_ = KBoundedSubspaceBases.ParentMethods._element_constructor_.__func__ _element_constructor = _element_constructor_ def _repr_(self): @@ -1299,9 +1299,9 @@ def __init__(self, kBoundedRing): # The following are meant to be inherited with the category framework, but # this fails because they are methods of Parent. The trick below overcomes # this problem. - __getitem__ = KBoundedSubspaceBases.ParentMethods.__getitem__.im_func - _repr_term = KBoundedSubspaceBases.ParentMethods._repr_term.im_func - _element_constructor_ = KBoundedSubspaceBases.ParentMethods._element_constructor_.im_func + __getitem__ = KBoundedSubspaceBases.ParentMethods.__getitem__.__func__ + _repr_term = KBoundedSubspaceBases.ParentMethods._repr_term.__func__ + _element_constructor_ = KBoundedSubspaceBases.ParentMethods._element_constructor_.__func__ _element_constructor = _element_constructor_ def _repr_(self): diff --git a/src/sage/misc/fpickle.pyx b/src/sage/misc/fpickle.pyx index f05c8a3e4a1..c8143a25cb1 100644 --- a/src/sage/misc/fpickle.pyx +++ b/src/sage/misc/fpickle.pyx @@ -86,31 +86,31 @@ def call_pickled_function(fpargs): # most functionality it provides def pickleMethod(method): 'support function for copy_reg to pickle method refs' - return unpickleMethod, (method.im_func.__name__, - method.im_self, + return unpickleMethod, (method.__func__.__name__, + method.__self__, method.im_class) def unpickleMethod(im_name, - im_self, + __self__, im_class): 'support function for copy_reg to unpickle method refs' try: unbound = getattr(im_class,im_name) - if im_self is None: + if __self__ is None: return unbound - bound=types.MethodType(unbound.im_func, - im_self) + bound=types.MethodType(unbound.__func__, + __self__) return bound except AttributeError: - assert im_self is not None,"No recourse: no instance to guess from." + assert __self__ is not None,"No recourse: no instance to guess from." # Attempt a common fix before bailing -- if classes have # changed around since we pickled this method, we may still be # able to get it by looking on the instance's current class. - unbound = getattr(im_self.__class__,im_name) - if im_self is None: + unbound = getattr(__self__.__class__,im_name) + if __self__ is None: return unbound - bound=types.MethodType(unbound.im_func, - im_self) + bound=types.MethodType(unbound.__func__, + __self__) return bound copy_reg.pickle(types.MethodType, diff --git a/src/sage/misc/function_mangling.pyx b/src/sage/misc/function_mangling.pyx index a54ae4bbd6c..354abcb27de 100644 --- a/src/sage/misc/function_mangling.pyx +++ b/src/sage/misc/function_mangling.pyx @@ -108,7 +108,7 @@ cdef class ArgumentFixer: sage: class one: ... def __init__(self, x = 1): ... self.x = x - sage: af = ArgumentFixer(one.__init__.im_func, classmethod=True) + sage: af = ArgumentFixer(one.__init__.__func__, classmethod=True) sage: af.fix_to_pos(1,2,3,a=31,b=2,n=3) ((1, 2, 3), (('a', 31), ('b', 2), ('n', 3))) diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index bf37acae44d..594fa8d7be4 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -1292,7 +1292,7 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return if inspect.isfunction(obj): func_obj = obj elif inspect.ismethod(obj): - func_obj = obj.im_func + func_obj = obj.__func__ elif isclassinstance(obj): if hasattr(obj,'_sage_src_'): #it may be a decorator! source = sage_getsource(obj) @@ -1638,7 +1638,7 @@ class ParentMethods: raise IOError('could not find class definition') if inspect.ismethod(object): - object = object.im_func + object = object.__func__ if inspect.isfunction(object): object = object.func_code if inspect.istraceback(object): diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index 7fe4ee7ef00..cc8518fb7ca 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -917,13 +917,13 @@ def __init__(self, f=None, **options): else: if hasattr(f, '__module__'): self.__module__ = f.__module__ - elif hasattr(f, 'im_func'): - self.__module__ = f.im_func.__module__ + elif hasattr(f, '__func__'): + self.__module__ = f.__func__.__module__ if hasattr(f, '__name__'): self.__name__ = f.__name__ - elif hasattr(f, 'im_func'): - self.__name__ = f.im_func.__name__ + elif hasattr(f, '__func__'): + self.__name__ = f.__func__.__name__ self.options = options