[New-bugs-announce] [issue27335] Clarify that writing to locals() inside a class body is supported

Steven D'Aprano report at bugs.python.org
Thu Jun 16 13:35:01 EDT 2016


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 at python
components: Documentation
messages: 268682
nosy: docs at 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 <report at bugs.python.org>
<http://bugs.python.org/issue27335>
_______________________________________


More information about the New-bugs-announce mailing list