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 like this: _privateObj= Object() def sorted(iteratorToSort=_privateObj): if iteratorToSort == _privateObj: raise TypeError('sorted is a classmethod of list ' + 'taking an iterator argument') else: <... 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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4