Opened 7 years ago

Closed 7 years ago

#17801 closed defect (invalid)

getattr_from_other_class() doesn't raise AttributeError if cls is not a type

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: misc Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #17800 Stopgaps:

Status badges

Description (last modified by jdemeyer)

The documentation of getattr_from_other_class (in src/sage/structure/misc.pyx) says:

    If self is an instance of cls, raises an ``AttributeError``, to
    avoid a double lookup.

But this only works correctly if cls is a type (not a Python class or a DynamicClass for example).

The <type>cls cast had to be added in #17800, otherwise one gets

sage -t src/sage/sets/set_from_iterator.py
**********************************************************************
File "src/sage/sets/set_from_iterator.py", line 805, in sage.sets.set_from_iterator.EnumeratedSetFromIterator_method_caller.__get__
Failed example:
    getattr_from_other_class(a, A, 'f')(4)
Exception raised:
    Traceback (most recent call last):
      File "/usr/local/src/sage-git/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 488, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/local/src/sage-git/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 850, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.sets.set_from_iterator.EnumeratedSetFromIterator_method_caller.__get__[4]>", line 1, in <module>
        getattr_from_other_class(a, A, 'f')(Integer(4))
      File "sage/structure/misc.pyx", line 251, in sage.structure.misc.getattr_from_other_class (build/cythonized/sage/structure/misc.c:1583)
        raise dummy_attribute_error
    AttributeError: 'instance' object has no attribute 'f'
**********************************************************************
File "src/sage/sets/set_from_iterator.py", line 814, in sage.sets.set_from_iterator.EnumeratedSetFromIterator_method_caller.__get__
Failed example:
    getattr_from_other_class(b, B, 'f')(2)
Exception raised:
    Traceback (most recent call last):
      File "/usr/local/src/sage-git/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 488, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/local/src/sage-git/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 850, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.sets.set_from_iterator.EnumeratedSetFromIterator_method_caller.__get__[7]>", line 1, in <module>
        getattr_from_other_class(b, B, 'f')(Integer(2))
      File "sage/structure/misc.pyx", line 251, in sage.structure.misc.getattr_from_other_class (build/cythonized/sage/structure/misc.c:1583)
        raise dummy_attribute_error
    AttributeError: 'instance' object has no attribute 'f'
**********************************************************************

Change History (5)

comment:1 Changed 7 years ago by jdemeyer

  • Description modified (diff)

comment:2 Changed 7 years ago by jdemeyer

  • Description modified (diff)

comment:3 Changed 7 years ago by jdemeyer

  • Dependencies set to #17800

comment:4 Changed 7 years ago by jdemeyer

  • Description modified (diff)
  • Summary changed from getattr_from_other_class() doesn't work properly if cls is not a type to getattr_from_other_class() doesn't raise AttributeError if cls is not a type

comment:5 Changed 7 years ago by jdemeyer

  • Milestone changed from sage-6.6 to sage-duplicate/invalid/wontfix
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.