Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list(ZZ) --> infinite loop #18378

Closed
nathanncohen mannequin opened this issue May 7, 2015 · 12 comments
Closed

list(ZZ) --> infinite loop #18378

nathanncohen mannequin opened this issue May 7, 2015 · 12 comments

Comments

@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented May 7, 2015

For some reason, list(something) breaks if __len__ raises a NotImplementedError, but a TypeError is ignored.

Python....

As len(NN) already raises a NotImplementedError, I just copied the behaviour.

Nathann

CC: @videlec

Component: basic arithmetic

Author: Nathann Cohen

Branch/Commit: 47cec14

Reviewer: Jean-Pierre Flori

Issue created by migration from https://trac.sagemath.org/ticket/18378

@nathanncohen nathanncohen mannequin added this to the sage-6.7 milestone May 7, 2015
@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented May 7, 2015

Branch: public/18378

@nathanncohen nathanncohen mannequin added the s: needs review label May 7, 2015
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 7, 2015

Commit: 9ba72b3

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 7, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

9ba72b3trac #18378: list(ZZ) --> infinite loop

@nathanncohen

This comment has been minimized.

@nbruin
Copy link
Contributor

nbruin commented May 7, 2015

comment:4

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...

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented May 7, 2015

comment:5

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.

Oh I see. Thanks ;-)

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 7, 2015

Changed commit from 9ba72b3 to 47cec14

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 7, 2015

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

47cec14trac #18378: list(ZZ) --> infinite loop

@jpflori
Copy link

jpflori commented May 18, 2015

Reviewer: Jean-Pierre Flori

@jpflori
Copy link

jpflori commented May 18, 2015

comment:7

Looks good enough to me, especially if NN already behaves like this.

@nathanncohen
Copy link
Mannequin Author

nathanncohen mannequin commented May 18, 2015

comment:8

Thanks !

Nathann

@vbraun
Copy link
Member

vbraun commented May 19, 2015

Changed branch from public/18378 to 47cec14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants