#5308: [with patch, positive review] Removing __len__ for combinatorial classes
(depend on #5200,#4549)
---------------------------+------------------------------------------------
Reporter: hivert | Owner: hivert
Type: enhancement | Status: assigned
Priority: major | Milestone: sage-3.4.2
Component: combinatorics | Keywords: __len__, count, combinatorial class
---------------------------+------------------------------------------------
Comment(by saliola):
Replying to [comment:12 mabshoff]:
> Hmm, one last thing: In {{{def __len__(self): }}} you deprecate
{{{__len__}}} and tell people to use count. Isn't it possible to deprecate
{{{__len__}}} and have it call count() automatically because that is the
way it is supposed to work.
It should say that one needs to use cardinality instead of {{{__len__}}}.
There are a few reasons why this doesn't work. One reason is that
{{{__len__}}} must return a Python int. So, if the CombinatorialClass is
too big, then calling {{{__len__}}} will raise an error, which is a bug.
Another problem is that some methods, like {{{__list__}}}, call
{{{__len__}}} behind the scenes. This means that there would be
deprecation warnings popping up in various places: for instance,
{{{list(Permutations(3))}}} would give a warning, and it would be very
confusing to a user not familiar with Python internals to see a warning
about using {{{__len__}}} when they didn't obviously call {{{__len__}}}.
Also the doctests would be littered with such deprecation warnings in
various places (whenever {{{list/filter/map}}} are called). Instead, we
decided to raise an {{{AttributeError}}}, which behaves nicely with
Python's specifications on how {{{__len__}}} is to behave when called by
{{{list/filter/map}}}, and also gives an appropriate error message when
{{{len}}} is called directly. It really is a special case, where the usual
deprecation procedure won't work.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5308#comment:13>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---