classification
Title: When using setattr identifiers can start with any character
Type: behavior Stage:
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: lnenov, loewis
Priority: normal Keywords:

Created on 2012-02-16 09:01 by lnenov, last changed 2012-02-16 09:22 by loewis. This issue is now closed.

Messages (2)
msg153468 - (view) Author: Lyudmil Nenov (lnenov) Date: 2012-02-16 09:01
I am not sure if this is actually a bug. 

Given documentation @ http://docs.python.org/release/2.5.2/ref/identifiers.html, the issue is that setattr does not appear to check identifier for naming convention.

See a short example below. Running on windows

>>> sys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)
>>> class Example():
	pass
>>> example = Example()
>>> example.@foo = 4
SyntaxError: invalid syntax
>>> setattr(example, '@foo', 'bar')
>>> dir(example)
['@foo', '__doc__', '__module__']
>>> example.@foo
SyntaxError: invalid syntax
>>> getattr(example, '@foo')
'bar'
msg153470 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-02-16 09:22
It's not a bug. The specification of identifiers refers only to the places where they appear in the language grammar, i.e. what you can put into source code. What parameters objects accept in __setattr__ is an entirely different question. Some objects may check for well-formedness, some objects may accept only a small number of identifiers (e.g. when they use __slots__), some may accept non-strings as attribute names.
History
Date User Action Args
2012-02-16 09:22:54loewissetstatus: open -> closed

nosy: + loewis
messages: + msg153470

resolution: not a bug
2012-02-16 09:01:59lnenovcreate