#18378: list(ZZ) --> infinite loop
-------------------------+-------------------------------------------------
       Reporter:         |        Owner:
  ncohen                 |       Status:  needs_review
           Type:         |    Milestone:  sage-6.7
  defect                 |   Resolution:
       Priority:  major  |    Merged in:
      Component:  basic  |    Reviewers:
  arithmetic             |  Work issues:
       Keywords:         |       Commit:
        Authors:         |  9ba72b347c17cf60cd7d5f0f7cda9185c33f9fa0
  Nathann Cohen          |     Stopgaps:
Report Upstream:  N/A    |
         Branch:         |
  public/18378           |
   Dependencies:         |
-------------------------+-------------------------------------------------

Comment (by nbruin):

 For posterity, the reason that `TypeError` gets caught is to make this
 work:
 {{{
 sage: l=(i for i in range(10))
 sage: len(l)
 TypeError: object of type 'generator' has no len()
 sage: list(l)
 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 }}}
 It may well be an accident that `list` checks `len` of its argument before
 it checks if it's iterable, so I would not consider changing the error
 type a reliable way to prevent an infinite loop. I don't think python
 officially supports a way of preventing `list(<infinite iterable>)` from
 going in an infinite loop. It works, though...

--
Ticket URL: <http://trac.sagemath.org/ticket/18378#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.

Reply via email to