Changes between Initial Version and Version 1 of Ticket #16280


Ignore:
Timestamp:
05/02/14 23:00:13 (6 years ago)
Author:
nthiery
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #16280

    • Property Cc sage-combinat ncohen vdelecroix added
    • Property Component changed from PLEASE CHANGE to combinatorics
    • Property Type changed from PLEASE CHANGE to defect
    • Property Authors changed from to Nicolas M. Thiéry
  • Ticket #16280 – Description

    initial v1  
     1*Problem*
     2
     3Before this ticket, a FiniteEnumeratedSet could not be called on it's
     4own elements whenever they were not Element's:
     5{{{
     6sage: F = FiniteEnumeratedSet(["a", 1])
     7sage: F(1)
     81
     9sage: F("a")
     10...
     11TypeError: Cannot convert str to sage.structure.element.Element
     12}}}
     13
     14This prevented the use of `F(x)` as generic idiom to convert `x` into
     15`F` while checking that it's in `F`.
     16
     17And indeed:
     18{{{
     19sage: TestSuite(F).run()
     20Failure in _test_an_element:
     21...
     22TypeError: Cannot convert str to sage.structure.element.Element
     23------------------------------------------------------------
     24The following tests failed: _test_an_element
     25}}}
     26
     27*Analysis*
     28
     29`Parent.__call__` enforces that `_element_constructor_` return an
     30`Element` (more precisely, it calls `_element_constructor_` through a
     31`DefaultConvertMap`, and any `Map` requires its results to be
     32instances of `Element`).
     33
     34*Proposed solution*
     35
     36Since `FiniteEnumeratedSets` is often a facade over plain Python
     37objects, this ticket works around this limitation by a custom
     38`FiniteEnumeratedSets.__call__` that calls directly
     39`_element_constructor_` whenever ``el`` is not an `Element`. Otherwise
     40`Parent.__call__` is called as usual.
     41
     42*Limitation*
     43
     44This workaround prevents conversions or coercions from facade parents
     45over plain Python objects. But it's already much better than before!