#16280: Fix call for FiniteEnumeratedSet's of plain Python objects
-------------------------------------+-------------------------------------
Reporter: nthiery | Owner:
Type: defect | Status: needs_review
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:
u/nthiery/fix_call_for_finite_enumeratedset_s_over_plain_python_objects|
8ac32c2d6854519a96eb1ce261240a0ee8537cb3
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Changes (by nthiery):
* status: new => needs_review
* commit: => 8ac32c2d6854519a96eb1ce261240a0ee8537cb3
Old 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!
New description:
*Problem*
Before this ticket, a `FiniteEnumeratedSet` could not be called on its
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!
--
Comment:
New commits:
||[http://git.sagemath.org/sage.git/commit/?id=8ac32c2d6854519a96eb1ce261240a0ee8537cb3
8ac32c2]||{{{#16280: Fix call for FiniteEnumeratedSet's of plain Python
objects}}}||
--
Ticket URL: <http://trac.sagemath.org/ticket/16280#comment:4>
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.