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

Set iteration is broken over sets created with iterators #3933

Closed
sagetrac-anakha mannequin opened this issue Aug 22, 2008 · 6 comments
Closed

Set iteration is broken over sets created with iterators #3933

sagetrac-anakha mannequin opened this issue Aug 22, 2008 · 6 comments
Assignees
Milestone

Comments

@sagetrac-anakha
Copy link
Mannequin

sagetrac-anakha mannequin commented Aug 22, 2008

This works:

sage: list(Set([1, 2, 3, 4, 5]))
[1, 2, 3, 4, 5]

But this doesn't:

sage: list(Set(iter([1, 2, 3, 4, 5])))
[]

Basically Set makes a Set_object() out of it and Set_object is really not prepared to deal with an iterator. I glanced over the code and did find an obvious solution.

Component: misc

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

@sagetrac-anakha
Copy link
Mannequin Author

sagetrac-anakha mannequin commented Aug 22, 2008

comment:1

The examples should read

sage: list(Set([1, 2, 3, 4, 5]))
[1, 2, 3, 4, 5]

and

sage: list(Set(iter([1, 2, 3, 4, 5])))
[]

@sagetrac-mabshoff sagetrac-mabshoff mannequin added this to the sage-3.1.2 milestone Aug 22, 2008
@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 23, 2009

comment:3

amusingly:

sage: list(Set(iter([1, 2, 3, 4, 5])))
[]
sage: list(Set(set(iter([1, 2, 3, 4, 5]))))
[1, 2, 3, 4, 5]

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 23, 2009

comment:4

Also, I was worried about giving it an infinite iterator, but it seems Python is happy to shoot itself in the foot:

sage: set(Primes())
<wait approximately forever for nothing to happen>

@rlmill
Copy link
Mannequin

rlmill mannequin commented Jan 23, 2009

comment:5

Attachment: trac-3933.patch.gz

@rlmill rlmill mannequin added the s: needs review label Jan 23, 2009
@sagetrac-abergeron
Copy link
Mannequin

sagetrac-abergeron mannequin commented Jan 24, 2009

comment:6

This works and passes tests. So I give it a positive review.

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Jan 25, 2009

comment:7

Merged in Sage 3.3.alpha3

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Jan 25, 2009
@sagetrac-mabshoff sagetrac-mabshoff mannequin modified the milestones: sage-3.4.1, sage-3.3 Jan 25, 2009
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

0 participants