Re: Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Steve D'Aprano
On Fri, 9 Dec 2016 01:51 am, Marco Buttu wrote: > Sometimes the Python name resolution is explained using a LEGB rule. > For instance, in [1] (I think also the Learning Python book gives the > same): > > "if a particular name:object mapping cannot be found in the local > namespaces, the

Re: Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Peter Otten
Chris Angelico wrote: > On Fri, Dec 9, 2016 at 5:03 AM, Peter Otten <__pete...@web.de> wrote: >>> The "usual optimization" is exactly what you describe: that different >>> bytecodes represent Local, Enclosing, and Global/Built-in scope >>> lookups. (Globals can be created or removed at run-time,

Re: Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Chris Angelico
On Fri, Dec 9, 2016 at 5:03 AM, Peter Otten <__pete...@web.de> wrote: >> The "usual optimization" is exactly what you describe: that different >> bytecodes represent Local, Enclosing, and Global/Built-in scope >> lookups. (Globals can be created or removed at run-time, so there's no >>

Re: Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Peter Otten
Chris Angelico wrote: > On Fri, Dec 9, 2016 at 1:51 AM, Marco Buttu wrote: >> "if a particular name:object mapping cannot be found in the local >> namespaces, the namespaces of the enclosed scope are being searched next. >> If the search in the enclosed scope is

Re: Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Chris Angelico
On Fri, Dec 9, 2016 at 1:51 AM, Marco Buttu wrote: > "if a particular name:object mapping cannot be found in the local > namespaces, the namespaces of the enclosed scope are being searched next. If > the search in the enclosed scope is unsuccessful, too, Python moves on to

Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Marco Buttu
Sometimes the Python name resolution is explained using a LEGB rule. For instance, in [1] (I think also the Learning Python book gives the same): "if a particular name:object mapping cannot be found in the local namespaces, the namespaces of the enclosed scope are being searched next. If the