Opened 9 years ago

Closed 9 years ago

#14486 closed defect (fixed)

0 == Set([0]) raises error

Reported by: vbraun Owned by: jason
Priority: major Milestone: sage-5.10
Component: misc Keywords:
Cc: ncohen, was, nthiery Merged in: sage-5.10.beta1
Authors: Volker Braun Reviewers: Nathann Cohen
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by ncohen)

See https://groups.google.com/d/msg/sage-devel/2y1knINMAy0/rev2RbskKgwJ

sage: 0 == Set([1]) 
... 
AttributeError: 'Set_object_enumerated_with_category' object has no 
attribute '_richcmp_' 

Apply :

Attachments (3)

trac_14486_set_coercion.patch (1.4 KB) - added by vbraun 9 years ago.
Updated patch
a.patch (621 bytes) - added by ncohen 9 years ago.
trac_14486-rev.patch (541 bytes) - added by ncohen 9 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 9 years ago by vbraun

  • Authors set to Volker Braun
  • Cc was nthiery added
  • Status changed from new to needs_review

Changed 9 years ago by vbraun

Updated patch

comment:2 Changed 9 years ago by vbraun

Forgot to also check for Python ints, should work now.

comment:3 Changed 9 years ago by ncohen

Oh, I see... Well, unless you see a more generic way to avoid the problem, could you also add floats to the list ?

sage: Set(float(0))      
Set of elements of 0.0
sage: list(Set(float(0)))
...
AttributeError: 'float' object has no attribute '__iter__'

I don't see anything else that we should avoid, but one never knows... ;

Oh !

sage: Set(True) 
...
ValueError: underlying object cannot be an integer

What about doing it on a "whitelist" base ? Something like "if is an iterable we accept to build a Set from it", and otherwise we refuse ?

Looks lke it is what frozenset does

sage: frozenset(1)
...
TypeError: 'sage.rings.integer.Integer' object is not iterable

I'm sorry for only coming with problems and not solutions ^^;

Nathann

comment:4 Changed 9 years ago by vbraun

Those are all problems with the Set factory function and not with the Set_object.__init__ constructor. Feel free to open a separate ticket for them.

comment:5 Changed 9 years ago by ncohen

Provided that I would spend the lifetime necessary to fix all broken doctests, what would be your idea of such a patch ?

Nathann

Changed 9 years ago by ncohen

comment:6 Changed 9 years ago by vbraun

The Set function should check that its argument is iterable using isinstance(X, collections.Iterable). This will probably uncover bugs in sage where iterables are not deriving from collections.Iterable that then need to be fixed up.

In a different ticket.

comment:7 Changed 9 years ago by ncohen

  • Description modified (diff)
  • Reviewers set to Nathann Cohen

Okayyyyyyyyyyyyyy ! Well, then if you agree with this ...

Nathann

Changed 9 years ago by ncohen

comment:8 Changed 9 years ago by vbraun

  • Status changed from needs_review to positive_review

comment:9 Changed 9 years ago by ncohen

THanks !

Nathann

comment:10 Changed 9 years ago by jdemeyer

  • Merged in set to sage-5.10.beta1
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.