copysort patch, was RE: [Python-Dev]inline sort option
mcherm at mcherm.com
Tue Oct 28 13:10:26 EST 2003
Alex Martelli writes:
> BTW, I think I should point out one POSSIBLE problem with
> classmethods -- since unfortunately they CAN be called on an
> instance, and will ignore that instance, this may confuse an
> unsuspecting user.
Alex, that's a good point, and one we should be careful of.
However, (as you said) I suspect that the unsuspecting users
will always call it with zero arguments. So long as that call
always fails (preferably with a useful error message) I think
we should be OK.
So what if we make the error message maximally useful? Something
if iteratorToSort == _privateObj:
raise TypeError('sorted is a classmethod of list ' +
'taking an iterator argument')
<... normal body here ...>
The only thing I've done here was to make the text of the message
more helpful (I've even left the type of the exception as TypeError
even though that might not be the most useful thing). Okay...
there's one other change... if you pass 2 or more arguments, then
it will complain that it expected "at least 0 arguments", but try
it once with 0 arguments and you'll immediately understand.
-- Michael Chermside
More information about the Python-Dev