[Python-Dev] bug or a feature? (original) (raw)
Scott Dial scott+python-dev at scottdial.com
Thu Jun 12 04:44:17 CEST 2008
- Previous message: [Python-Dev] bug or a feature?
- Next message: [Python-Dev] bug or a feature?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Maciej Fijalkowski wrote:
On Thu, Jun 12, 2008 at 2:32 AM, Terry Reedy <tjreedy at udel.edu> wrote:
"Scott Dial" <scott+python-dev at scottdial.com> wrote in message news:4850263A.3040805 at scottdial.com... || If non-string keys are not allowed in dict, then the AddOns library | should be changed to add another dict to the object of interest to track | these AddOn instances.
There are three possibilities with respect to dict and non-string keys. 1. All implementations must reject such. 2. Each implementation decides for itself. 3. All implementations must allow such. Current, CPython does not reject, eliminating 1). Since, as I understand it, at least 1 other implementation does reject, 3) is also eliminated until Guido decrees otherwise and such implementation(s) change. This leaves 2) as the de facto situation, but this could be made clearer in the docs: "The result of trying to add non-string keys to any dict attribute is implementation defined." This means that portable Python code must act as if 1) were the case. This is completely irrelevant. This post is not about assigning non-string stuff to dict of class which works completely fine. It's about abusing locals, which are not even given that they'll modify this dict.
Not withstanding Terry's respond, this is not as off-topic as you make it out to be. The test case you cited is in fact test this exact 'feature'. And as Terry expounded on it, it was unclear to me whether that was even of allowed. The only reason the test used locals() was because it was the only way to insert a non-string key into the class namespace.
class A: ... locals()[42] = 98 A.dict {'module': 'main', 43: 1, 'doc': None}
locals() has to be used because dict is unavailable at definition.
class A: ... dict[42] = 98 NameError: name 'dict' is not defined
So, while one can write:
class A: pass a.dict[42] = 98
But that's not quite the same. Nevertheless, it was still unclear whether there was any pronouncements on non-string keys. Sorry for wasting your time.
-Scott
-- Scott Dial scott at scottdial.com scodial at cs.indiana.edu
- Previous message: [Python-Dev] bug or a feature?
- Next message: [Python-Dev] bug or a feature?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]