[Tutor] Need Explanation...

Lie Ryan lie.1296 at gmail.com
Sun Dec 11 04:23:31 CET 2011


On 12/11/2011 04:04 AM, Alan Gauld wrote:
> On 10/12/11 16:46, Steven D'Aprano wrote:
>> circumstances, regardless of which behaviour was choosen for append, it
>> would catch out some people some time.
>
> Probably, although if returning 'self' were the default (which
> of course only makes sense in a pure OO world like Smalltalk) people
> would get used to the semantics. Consistency is all in these kinds of
> situations. Sadly its one of the few areas where Python is slightly
> inconsistent.

If returning 'self' is the default expected behavior, it would cause 
inconsistencies with respect to immutable types. For example, `5 
.__add__(2)`, one could expect it to return 5 instead of 7.

While I liked the attraction of "fluent interface" of being able to 
easily chain function calls, it is inherently more inconsistent than 
what Python are doing.



More information about the Tutor mailing list