Changes between Version 32 and Version 33 of Ticket #20767


Ignore:
Timestamp:
08/04/16 06:55:06 (5 years ago)
Author:
jdemeyer
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #20767 – Description

    v32 v33  
    1 Move all coercion logic from `RingElement`, `ModuleElement` and the like to `Element`.
     1This ticket has 2 main changes:
    22
    3 The main consequence is that it matters a lot less whether a class inherits from `Element` or from `ModuleElement`/`RingElement`/`FieldElement`...
     31. Move all coercion logic from `RingElement`, `ModuleElement` and the like to `Element`.
    44
    5 One difference between `Element` and more specialized classes like `RingElement` remains: the more specialized classes have some default implementations for arithmetic. For example, `ModuleElement` implements unary negation as multiplication by -1. The base class `Element` has no such default implementations.
     5Because of this, it matters a lot less whether a class inherits from `Element` or from `ModuleElement`/`RingElement`/`FieldElement`...
     6
     7One difference remains: the more specialized classes have some default implementations for arithmetic. For example, `ModuleElement` implements unary negation as multiplication by -1. The base class `Element` has no such default implementations.
    68
    79This patch also affects lookup in categories: with this patch, double-underscore methods like `__add__` are never taken from the category. The `Element` classes take precedence over the category, so the default implementations of arithmetic operations will override whatever is in the category (this is existing behaviour, not affected by this patch). For the base class `Element`, this is not an issue since there are no default implementations.
     10
     112. Change the implementation of double-underscore methods like `__add__` to return `NotImplemented` if one argument is not a Sage `Element` and coercion fails.
     12
     13This will cause Python to try the reversed operation (`__radd__` or `__add__` in Cython). This way, Sage has improved support for operations with non-Sage types.