[docs] [issue25205] setattr accepts invalid identifiers

eryksun report at bugs.python.org
Mon Sep 21 23:41:18 CEST 2015

eryksun added the comment:

The name can be any str/unicode string, including language keywords: 

    >>> setattr(o, 'def', 'allowed')
    >>> getattr(o, 'def')
    >>> o.def
      File "<stdin>", line 1
    SyntaxError: invalid syntax

and even an empty string:

    >>> setattr(o, '', 'mu')
    >>> getattr(o, '')

This includes instances of str and unicode subclasses, at least in CPython.

assignee:  -> docs at python
components: +Documentation
nosy: +docs at python, eryksun
priority: normal -> low
versions:  -Python 2.7

Python tracker <report at bugs.python.org>

More information about the docs mailing list