En Wed, 19 Nov 2008 11:56:28 -0200, Mark Dickinson <[EMAIL PROTECTED]> escribió:
On Nov 19, 12:39 pm, srinivasan srinivas <[EMAIL PROTECTED]>
wrote:
a1 = fs(1,2,3)
a2 = fs(3,4,5)
print a1.difference(a2)
Error:
    return "%s(%r)" % (self.__class__.__name__, self.__data)
AttributeError: 'fs' object has no attribute '_fs__data'
I guess you need to implement the difference method in your
subclass.

It's a little odd that an operation on subclasses of frozenset returns
an instance of the subclass, rather than simply a frozenset. Most
other
Python types don't work that way.  Compare and contrast:
Yep; looks like a bug in the set/frozenset implementation. Usually builtin  
types don't return subclasses because they don't know how the constructor  
should be called - it is indeed the case here, as the OP has changed  
frozenset.__new__ signature. Even if fs.__new__ were called its arguments  
would be wrong.
The bug is not that the subclass constructor is skipped, but that  
a1.difference(a2) returns a subclass instead of a frozenset instance.
(set and frozenset are unrelated types but share a lot of their  
implementation by using generic algorithms, and it's the generic part the  
culprit here)
--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to