[issue25205] setattr accepts invalid identifiers

2018-10-29 Thread STINNER Victor


STINNER Victor  added the comment:

I created bpo-35105 to propose to document the behavior.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2018-10-29 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> not a bug
stage:  -> resolved
status: pending -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2018-04-22 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-23 Thread eryksun

eryksun added the comment:

Even MvL appears to slip up when he states "some may accept non-strings as 
attribute names". That would be pointless in a __setattr__ method since setattr 
/ PyObject_SetAttr reject non-string values as 'names'.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-23 Thread R. David Murray

R. David Murray added the comment:

I did however make the same mistake without checking the docs or the behavior.  
But the fact that I didn't look at it doesn't make the current documentation 
wrong :)

What change is it that you think would be beneficial?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-22 Thread W deW

W deW added the comment:

Thanks for the ref to issue14029. I think I see how it works. As long as the 
object's __dict__ accepts the attributeName as a key, it needs not be a valid 
string nor a string at all. Though the latter *is* checked for, and that in 
turn can be circumvented by adding the attribute to the __dict__ directly. An 
object can be made attribute to itself.

However, the documentation falls short here. So far, I haven't found where it 
defines "attribute". Is there any point in defining an attribute that cannot be 
addressed as an attribute if the parser doesn't allow it?

It seems to me that in order to catch programing errors early, the default 
behaviour should include checking the valid syntax of the attribute's name.

--
components:  -Documentation
versions: +Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-22 Thread eryksun

eryksun added the comment:

This is a documentation issue and not specific to a particular version  of 
Python. What's the rule on version tagging in this case?

--
components: +Documentation

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-22 Thread Martin Panter

Martin Panter added the comment:

Eryksun: If you mean tagging the bug report, I think we usually tag all the 
applicable open branches that are due for another release.

I’m not sure anything needs to be documented regarding setattr(). At best it is 
an implementation detail that should not be relied on, although making the 
implementation stricter could be a compatibility problem.

There are other places where troublesome names are allowed. One that caught my 
eye recently is os.sendfile(in=..., ...) is a syntax error, but you can still 
pass the “in” keyword via os.sendfile(**{"in": ...}, ...).

--
versions: +Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-21 Thread Martin Panter

Martin Panter added the comment:

Previous report: Issue 14029

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-21 Thread STINNER Victor

STINNER Victor added the comment:

Even if it's not well document, it's legit and supported by CPython, but it may 
not be supported by other Python implementation (ex: PyPy).

--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-21 Thread W deW

New submission from W deW:

An identifier is defined by 

identifier ::=  (letter|"_") (letter | digit | "_")*

setattr accepts identifiers that do not meet this criterion:


Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class C(object): pass
...
>>> o=C()
>>> setattr(o, "$$$", True)
>>>  dir(o)
['$$$', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', 
'__getattribute__', '__hash__', '__in
module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__sizeof__', '__str__', '__su
__', '__weakref__']
>>> o.$$$
  File "", line 1
o.$$$
  ^
SyntaxError: invalid syntax
>>>


--
components: Interpreter Core
messages: 251248
nosy: W deW
priority: normal
severity: normal
status: open
title: setattr accepts invalid identifiers
type: behavior
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-21 Thread eryksun

eryksun added the comment:

To clarify using a unicode name in 2.x, it has to be encodable using the 
default encoding, sys.getdefaultencoding(). Normally this is ASCII.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25205] setattr accepts invalid identifiers

2015-09-21 Thread eryksun

eryksun added the comment:

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

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

and even an empty string:

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

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

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

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com