[issue34961] Global scoping when shadowing local names in class definitions
New submission from multun : Hello, >>> a="global" >>> def func(a): ... class wtf(): ... a=a ... return wtf ... >>> func("local").a 'global' >>> def func2(a): ... class wtf(): ... b=a ... return wtf ... >>> func2("local").b 'local' Is this behavior legit ? Best regards, -- Victor "multun" Collod -- components: Interpreter Core files: weird_class_scope.py messages: 327547 nosy: multun priority: normal severity: normal status: open title: Global scoping when shadowing local names in class definitions type: behavior versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8 Added file: https://bugs.python.org/file47862/weird_class_scope.py ___ Python tracker <https://bugs.python.org/issue34961> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue34961] Global scoping when shadowing local names in class definitions
multun added the comment: Closing, this is documented, and as such most likely intended. "A class definition is an executable statement that may use and define names. These references follow the normal rules for name resolution with an exception that unbound local variables are looked up in the global namespace." https://docs.python.org/3.7/reference/executionmodel.html#builtins-and-restricted-execution -- resolution: -> not a bug stage: -> resolved status: open -> closed versions: +Python 2.7, Python 3.4, Python 3.5 ___ Python tracker <https://bugs.python.org/issue34961> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com