Method Chaining
Ethan Furman
ethan at stoneleaf.us
Sun Jun 19 11:01:53 EDT 2016
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.
--
~Ethan~
More information about the Python-list
mailing list