Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #20767: Move coercion to Element
This ticket has 2 main changes: 1. Move all coercion logic from `RingElement`, `ModuleElement` and the like to `Element`. Because of this, it matters a lot less whether a class inherits from `Element` or from `ModuleElement`/`RingElement`/`FieldElement`... One 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. This 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. 2. Change the implementation of double-underscore methods like `__add__` to return `NotImplemented` (rather than raise an error) if one argument is not a Sage `Element` and coercion fails. This 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. URL: https://trac.sagemath.org/20767 Reported by: jdemeyer Ticket author(s): Jeroen Demeyer Reviewer(s): Nicolas M. Thiéry
- Loading branch information