New submission from Steven D'Aprano:

The docs for locals() warn not to write to the dict returned, as it may not 
have the intended effect of modifying the actual variables seen by the 
interpreter.

https://docs.python.org/3/library/functions.html#locals

But as I understanding it, using locals() inside a class body is intentionally 
supported:

    class K:
        locals()['x'] = 1
    
    assert K.x == 1

is not just an accident of implementation, but the intended behaviour and a 
language guarantee.

----------
assignee: docs@python
components: Documentation
messages: 268682
nosy: docs@python, steven.daprano
priority: normal
severity: normal
status: open
title: Clarify that writing to locals() inside a class body is supported
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27335>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to