Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #19733: Assignment of special methods does not work in Cython
In Cython, you cannot do {{{ cdef class Foo: __str__ = whatever }}} and expect it to work. I asked upstream about this: [https://groups.google.com/forum/#!topic /cython-users/aE7Tn-XLZnI] ------- When deriving a `class` (not `cdef class`) this kind of assignment suddenly works:: {{{ cdef class Base(object): def my_str(self): return "good" __str__ = my_str class Derived(Base): pass }}} gives {{{ sage: str(Base()) '<_home_jdemeyer__sage_temp_tamiyo_8430_tmp__MunIM_spyx_0.Base object at 0x7fb54ae544d0>' sage: str(Derived()) 'good' }}} This also explains why the `__len__ = cardinality` in `src/sage/rings/finite_rings/finite_field_base.pyx` works. It doesn't work on the level of `sage.rings.finite_rings.finite_field_base.FiniteField`, but it works at the level of the actual finite field classes (which are Python classes). URL: http://trac.sagemath.org/19733 Reported by: jdemeyer Ticket author(s): Jeroen Demeyer Reviewer(s): Dima Pasechnik
- Loading branch information