Method Chaining

Joonas Liik liik.joonas at gmail.com
Sat Jun 18 10:05:25 EDT 2016


On 18 June 2016 at 15:04, Pete Forman <petef4+usenet at gmail.com> wrote:
> Rustom Mody <rustompmody at gmail.com> writes:
>
>> On Friday, June 17, 2016 at 2:58:19 PM UTC+5:30, Steven D'Aprano wrote:
>>> On Fri, 17 Jun 2016 06:13 pm, Ned Batchelder wrote:
>>>
>>> > To me, it's a toss-up. The chained version is nice in that it
>>> > removes the repetition of "g". But the unchained version is more
>>> > explicit, and avoids the awkward parenthesis.
>>> >
>>> > I think I would lean toward the unchained version. Clearly tastes
>>> > can differ.
>>>
>>> Indeed. For what it's worth, I'm ever-so-slightly leaning towards
>>> Lawrence's taste here.
>>
>> More than 'slightly' out here!
>> One thing about python OOP that irritates me is the 'self.' clutter.
>> With a Pascal/VB style with-statement its naturally taken care of
>>
>> Yeah I know there is this FAQ:
>> https://docs.python.org/2/faq/design.html#why-doesn-t-python-have-a-with-statement-for-attribute-assignments
>>
>> I consider it bogus if we allow with to mean something like:
>> https://msdn.microsoft.com/en-us/library/wc500chb.aspx
>
> One subtle difference between your two citations is that VB uses a
> leading dot. Might that lessening of ambiguity enable a future Python to
> allow this?
>
> class Foo:
>     def .set(a):  # equivalent to def set(self, a):
>         .a = a    # equivalent to self.a = a
>
> Unless it is in a with statement
>
> with obj:
>     .a = 1                # equivalent to obj.a = 1
>     .total = .total + 1   # obj.total = obj.total + 1
>
> --
> Pete Forman
> --
> https://mail.python.org/mailman/listinfo/python-list

the leading dot does not resolve the ambiguity that arises from:

with ob_a:
    with ob_b:
        .attr_c = 42 # which object are we modifying right now?

also refer to "javascript the bad parts" about all the edege cases
that python would surely face.
also with is allready used for context managers..



More information about the Python-list mailing list