Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #110145

Re: Method Chaining

From Ethan Furman <ethan@stoneleaf.us>
Newsgroups comp.lang.python
Subject Re: Method Chaining
Date 2016-06-19 08:56 -0700
Message-ID <mailman.139.1466351802.2288.python-list@python.org> (permalink)
References (9 earlier) <5765B36F.5010506@stoneleaf.us> <CAB1GNpSStN+eQfwyMk02QbaRQscn5DSK-FwNozXE+2Gf0EYPAA@mail.gmail.com> <5766B3E1.2020807@stoneleaf.us> <dcbfb505-5a4b-a4af-51d3-f6ee78923cac@gmail.com> <5766C0BC.1070009@stoneleaf.us>

Show all headers | View raw


On 06/19/2016 08:14 AM, Michael Torrie wrote:
> On 06/19/2016 09:01 AM, Ethan Furman wrote:
>> On 06/19/2016 04:56 AM, Joonas Liik wrote:
>>> On 18 June 2016 at 23:47, Ethan Furman wrote:
>>>> On 06/18/2016 07:05 AM, Joonas Liik wrote:

>>>>> 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?
>>>>
>>>>
>>>> The innermost one.  Why would it be anything else?
>>>
>>> What if ob_b does not have attribute attr_c but ob_a does?
>>
>> Good question.  I would say that _only_ the innermost with object is
>> searched, and if it doesn't have the requested attribute an
>> AttributeError is raised.  Otherwise, as you say, it could be a
>> nightmare to maintain.
>
> But that wouldn't work either because it would make it impossible to
> *set* attributes on an object.

Sure it would, just like any 'this_thing.whatever = 9' works just fine 
if 'this_thing' doesn't already a `whatever` attribute.

The only thing that would change is being able to omit the 'this_thing' 
portion; if you want to access an earlier 'with' obj, then you must be 
explicit:

   with ob_a:
      with ob_b:
         ob_a.whatever = 9
         .something_else = 10

> Python's dynamic nature just doesn't lend itself to this kind of ambiguity.

This is no more ambiguous than any other nested structure and, in some 
cases, even simpler.

--
~Ethan

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-16 19:02 -0700
  Re: Method Chaining Steven D'Aprano <steve@pearwood.info> - 2016-06-17 12:39 +1000
  Re: Method Chaining Michael Selik <michael.selik@gmail.com> - 2016-06-17 04:23 +0000
    Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-16 21:37 -0700
      Re: Method Chaining Ned Batchelder <ned@nedbatchelder.com> - 2016-06-17 01:13 -0700
        Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-17 01:38 -0700
          Re: Method Chaining Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-06-17 11:45 +0300
        Re: Method Chaining Steven D'Aprano <steve@pearwood.info> - 2016-06-17 19:28 +1000
          Re: Method Chaining Michael Selik <michael.selik@gmail.com> - 2016-06-17 13:34 +0000
            Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-17 15:26 -0700
              Re: Method Chaining Michael Selik <michael.selik@gmail.com> - 2016-06-17 22:45 +0000
              Re: Method Chaining Michael Selik <michael.selik@gmail.com> - 2016-06-17 23:10 +0000
          Re: Method Chaining Rustom Mody <rustompmody@gmail.com> - 2016-06-17 09:48 -0700
            Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-17 15:25 -0700
            Re: Method Chaining Pete Forman <petef4+usenet@gmail.com> - 2016-06-18 13:04 +0100
              Re: Method Chaining Joonas Liik <liik.joonas@gmail.com> - 2016-06-18 17:05 +0300
                Re: Method Chaining Pete Forman <petef4+usenet@gmail.com> - 2016-06-18 16:42 +0100
              Re: Method Chaining Rustom Mody <rustompmody@gmail.com> - 2016-06-18 08:35 -0700
                Re: Method Chaining Pete Forman <petef4+usenet@gmail.com> - 2016-06-19 11:16 +0100
              Re: Method Chaining Ethan Furman <ethan@stoneleaf.us> - 2016-06-18 13:47 -0700
              Re: Method Chaining Joonas Liik <liik.joonas@gmail.com> - 2016-06-19 14:56 +0300
              Re: Method Chaining Ethan Furman <ethan@stoneleaf.us> - 2016-06-19 08:01 -0700
              Re: Method Chaining Michael Torrie <torriem@gmail.com> - 2016-06-19 09:14 -0600
              Re: Method Chaining Ethan Furman <ethan@stoneleaf.us> - 2016-06-19 08:56 -0700
                Re: Method Chaining Rustom Mody <rustompmody@gmail.com> - 2016-06-19 09:03 -0700
        Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-17 15:22 -0700
          Re: Method Chaining Ned Batchelder <ned@nedbatchelder.com> - 2016-06-17 17:02 -0700

csiph-web