#16280: Fix FiniteEnumeratedSet's call to accept Python objects as input
-------------------------------------+------------------------
       Reporter:  nthiery            |        Owner:
           Type:  defect             |       Status:  new
       Priority:  major              |    Milestone:  sage-6.2
      Component:  combinatorics      |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Nicolas M. Thiéry  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
   Dependencies:                     |     Stopgaps:
-------------------------------------+------------------------
Changes (by {'newvalue': u'Nicolas M. Thi\xe9ry', 'oldvalue': ''}):

 * cc: sage-combinat, ncohen, vdelecroix (added)
 * component:  PLEASE CHANGE => combinatorics
 * type:  PLEASE CHANGE => defect
 * author:   => Nicolas M. Thiéry


Old description:



New description:

 *Problem*

 Before this ticket, a FiniteEnumeratedSet could not be called on it's
 own elements whenever they were not Element's:
 {{{
 sage: F = FiniteEnumeratedSet(["a", 1])
 sage: F(1)
 1
 sage: F("a")
 ...
 TypeError: Cannot convert str to sage.structure.element.Element
 }}}

 This prevented the use of `F(x)` as generic idiom to convert `x` into
 `F` while checking that it's in `F`.

 And indeed:
 {{{
 sage: TestSuite(F).run()
 Failure in _test_an_element:
 ...
 TypeError: Cannot convert str to sage.structure.element.Element
 ------------------------------------------------------------
 The following tests failed: _test_an_element
 }}}

 *Analysis*

 `Parent.__call__` enforces that `_element_constructor_` return an
 `Element` (more precisely, it calls `_element_constructor_` through a
 `DefaultConvertMap`, and any `Map` requires its results to be
 instances of `Element`).

 *Proposed solution*

 Since `FiniteEnumeratedSets` is often a facade over plain Python
 objects, this ticket works around this limitation by a custom
 `FiniteEnumeratedSets.__call__` that calls directly
 `_element_constructor_` whenever ``el`` is not an `Element`. Otherwise
 `Parent.__call__` is called as usual.

 *Limitation*

 This workaround prevents conversions or coercions from facade parents
 over plain Python objects. But it's already much better than before!

--

--
Ticket URL: <http://trac.sagemath.org/ticket/16280#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to