Re: Curious case of UnboundLocalError

2018-03-31 Thread Peter Otten
Johannes Bauer wrote: > On 30.03.2018 13:25, Johannes Bauer wrote: > >>> This mention of collections refers to ... >>> } for (_, collections) in z.items(): >>> >>> ... this local variable. >> >> Yup, but why? I mean, at the point of definition of "z", the only >> definition of

Re: Curious case of UnboundLocalError

2018-03-31 Thread Johannes Bauer
On 30.03.2018 16:46, Ben Bacarisse wrote: >> Yup, but why? I mean, at the point of definition of "z", the only >> definition of "collections" that would be visible to the code would be >> the globally imported module, would it not? How can the code know of the >> local declaration that only comes

Re: Curious case of UnboundLocalError

2018-03-30 Thread Terry Reedy
On 3/30/2018 7:25 AM, Johannes Bauer wrote: On 30.03.2018 13:13, Ben Bacarisse wrote: import collections class Test(object): def __init__(self): z = { "y": collections.defaultdict(list), This mention of collections refers to ...

Re: Curious case of UnboundLocalError

2018-03-30 Thread Ben Bacarisse
Johannes Bauer writes: > On 30.03.2018 13:13, Ben Bacarisse wrote: > >>> import collections >>> >>> class Test(object): >>> def __init__(self): >>> z = { >>> "y": collections.defaultdict(list), >> >> This mention of collections refers to

Re: Curious case of UnboundLocalError

2018-03-30 Thread Johannes Bauer
On 30.03.2018 13:25, Johannes Bauer wrote: >> This mention of collections refers to ... >> >>> } >>> for (_, collections) in z.items(): >> >> ... this local variable. > > Yup, but why? I mean, at the point of definition of "z", the only > definition of "collections" that

Re: Curious case of UnboundLocalError

2018-03-30 Thread Chris Angelico
On Fri, Mar 30, 2018 at 9:24 PM, Johannes Bauer wrote: > Hey group, > > I stumbled about something that I cannot quite explain while doing some > stupid naming of variables in my code, in particular using "collections" > as an identifier. However, what results is strange.

Re: Curious case of UnboundLocalError

2018-03-30 Thread Johannes Bauer
On 30.03.2018 13:13, Ben Bacarisse wrote: >> import collections >> >> class Test(object): >> def __init__(self): >> z = { >> "y": collections.defaultdict(list), > > This mention of collections refers to ... > >> } >> for (_,

Re: Curious case of UnboundLocalError

2018-03-30 Thread Ben Bacarisse
Johannes Bauer writes: > I stumbled about something that I cannot quite explain while doing some > stupid naming of variables in my code, in particular using "collections" > as an identifier. However, what results is strange. I've created a > minimal example. Consider this: