Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Phillip J. Eby
At 08:32 PM 6/11/2008 -0400, Terry Reedy wrote: The Data Model chapter of the Reference Manual lists .__dict__ as a special attribute of callables, modules, classes, and instances. It describes __dict__ as a namespace dictionary or implementation of the namespace thereof. Since namespaces map

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Phillip J. Eby
At 02:59 AM 6/12/2008 +0200, Maciej Fijalkowski wrote: It's about abusing locals, which are not even given that they'll modify this dict. Note that class bodies are a special case: as of PEP 3115, it's possible for a class body's locals to be a non-dictionary object, so it makes no sense to

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Carl Friedrich Bolz
Phillip J. Eby wrote: At 08:32 PM 6/11/2008 -0400, Terry Reedy wrote: The Data Model chapter of the Reference Manual lists .__dict__ as a special attribute of callables, modules, classes, and instances. It describes __dict__ as a namespace dictionary or implementation of the namespace

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Phillip J. Eby
At 01:34 PM 6/12/2008 +0200, Carl Friedrich Bolz wrote: Phillip J. Eby wrote: As it happens, most objects' __dict__ slots are settable by default, and *require* that you set it to a dict or subclass thereof. This is wrong for types: Which is why I said most - to exclude types, and objects

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Carl Friedrich Bolz
Phillip J. Eby wrote: At 01:34 PM 6/12/2008 +0200, Carl Friedrich Bolz wrote: Phillip J. Eby wrote: As it happens, most objects' __dict__ slots are settable by default, and *require* that you set it to a dict or subclass thereof. This is wrong for types: Which is why I said most - to

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Willem Broekema
On Thu, Jun 12, 2008 at 2:56 PM, Carl Friedrich Bolz [EMAIL PROTECTED] wrote: Of course attribute name lookups are affected, because you can have a non-string key that has a __hash__ and __eq__ method to make it look sufficiently like a string to the dict. Then the attribute lookup needs to

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Armin Rigo
Hi, On Wed, Jun 11, 2008 at 10:44:17PM -0400, Scott Dial wrote: The only reason the test used locals() was because it was the only way to insert a non-string key into the class namespace. This discussion is mistakenly focused on locals(). There is a direct way to have arbitrary keys in the

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Terry Reedy
Phillip J. Eby [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | At 08:32 PM 6/11/2008 -0400, Terry Reedy wrote: | The Data Model chapter of the Reference Manual lists .__dict__ as a special | attribute of callables, modules, classes, and instances. It describes | __dict__ as a

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Guido van Rossum
On Thu, Jun 12, 2008 at 8:24 AM, Armin Rigo [EMAIL PROTECTED] wrote: This discussion is mistakenly focused on locals(). There is a direct way to have arbitrary keys in the dict of a type: MyClass = type('MyClass', (Base,), {42: 64}) MyClass.__dict__[42] 64 There is, however, no way to

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Willem Broekema
On Thu, Jun 12, 2008 at 9:46 PM, Guido van Rossum [EMAIL PROTECTED] wrote: The intention was for these dicts to be used as namespaces. I think of it as follows: (a) Using non-string keys is a no-no, but the implementation isn't required to go out of its way to forbid it. That will allow

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Phillip J. Eby
At 12:46 PM 6/12/2008 -0700, Guido van Rossum wrote: The intention was for these dicts to be used as namespaces. By these do you mean type object __dict__ attributes, or *all* __dict__ attributes? ___ Python-Dev mailing list Python-Dev@python.org

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Guido van Rossum
On Thu, Jun 12, 2008 at 1:01 PM, Willem Broekema [EMAIL PROTECTED] wrote: On Thu, Jun 12, 2008 at 9:46 PM, Guido van Rossum [EMAIL PROTECTED] wrote: The intention was for these dicts to be used as namespaces. I think of it as follows: (a) Using non-string keys is a no-no, but the

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Guido van Rossum
On Thu, Jun 12, 2008 at 2:42 PM, Phillip J. Eby [EMAIL PROTECTED] wrote: At 12:46 PM 6/12/2008 -0700, Guido van Rossum wrote: The intention was for these dicts to be used as namespaces. By these do you mean type object __dict__ attributes, or *all* __dict__ attributes? Hadn't thought of

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Frank Wierzbicki
On Wed, Jun 11, 2008 at 5:50 AM, Nick Coghlan [EMAIL PROTECTED] wrote: Greg Ewing wrote: Implementations are also permitted to restrict namespace dictionaries to only accept string keys (I believe Jython does this for performance reasons - CPython just optimised the hell out of normal

Re: [Python-Dev] bug or a feature?

2008-06-12 Thread Guido van Rossum
On Thu, Jun 12, 2008 at 8:19 PM, Frank Wierzbicki [EMAIL PROTECTED] wrote: On Wed, Jun 11, 2008 at 5:50 AM, Nick Coghlan [EMAIL PROTECTED] wrote: Greg Ewing wrote: Implementations are also permitted to restrict namespace dictionaries to only accept string keys (I believe Jython does this for

Re: [Python-Dev] bug or a feature?

2008-06-11 Thread Nick Coghlan
Greg Ewing wrote: Maciej Fijalkowski wrote: What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. Do we consider it part of python language? Modifying the dict returned by locals() is documented as NOT being guaranteed to work, isn't it? Yep - it

Re: [Python-Dev] bug or a feature?

2008-06-11 Thread Phillip J. Eby
At 03:37 AM 6/11/2008 +0200, Maciej Fijalkowski wrote: On Wed, Jun 11, 2008 at 3:36 AM, Scott Dial [EMAIL PROTECTED] wrote: Maciej Fijalkowski wrote: What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. I apologize for my ignorance, but who?

Re: [Python-Dev] bug or a feature?

2008-06-11 Thread Scott Dial
Phillip J. Eby wrote: That test is there to ensure that it interoperates with code using the AddOns library from the Cheeseshop; SQLAlchemy is not the source of the usage. Now that's interesting. The AddOns library uses class objects as keys in the __dict__, but that doesn't says anything

Re: [Python-Dev] bug or a feature?

2008-06-11 Thread Terry Reedy
Scott Dial [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] || 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

Re: [Python-Dev] bug or a feature?

2008-06-11 Thread Maciej Fijalkowski
On Thu, Jun 12, 2008 at 2:32 AM, Terry Reedy [EMAIL PROTECTED] wrote: Scott Dial [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] || 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 |

Re: [Python-Dev] bug or a feature?

2008-06-11 Thread Terry Reedy
Maciej Fijalkowski [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | On Thu, Jun 12, 2008 at 2:32 AM, Terry Reedy [EMAIL PROTECTED] wrote: | | Scott Dial [EMAIL PROTECTED] wrote in message | news:[EMAIL PROTECTED] | || If non-string keys are not allowed in __dict__, then the AddOns

Re: [Python-Dev] bug or a feature?

2008-06-11 Thread Scott Dial
Maciej Fijalkowski wrote: On Thu, Jun 12, 2008 at 2:32 AM, Terry Reedy [EMAIL PROTECTED] wrote: Scott Dial [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] || If non-string keys are not allowed in __dict__, then the AddOns library | should be changed to add another dict to the object

[Python-Dev] bug or a feature?

2008-06-10 Thread Maciej Fijalkowski
What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. Do we consider it part of python language? (Note that you cannot do the same with getattr/setattr which checks if argument is a string) Cheers, fijal ___

Re: [Python-Dev] bug or a feature?

2008-06-10 Thread Benjamin Peterson
On Tue, Jun 10, 2008 at 8:10 PM, Maciej Fijalkowski [EMAIL PROTECTED] wrote: What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. Do we consider it part of python language? (Note that you cannot do the same with getattr/setattr which checks if

Re: [Python-Dev] bug or a feature?

2008-06-10 Thread Steve Holden
Benjamin Peterson wrote: On Tue, Jun 10, 2008 at 8:10 PM, Maciej Fijalkowski [EMAIL PROTECTED] wrote: What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. Do we consider it part of python language? (Note that you cannot do the same with

Re: [Python-Dev] bug or a feature?

2008-06-10 Thread Scott Dial
Maciej Fijalkowski wrote: What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. I apologize for my ignorance, but who? Could you please cite something reputable that relies on this detail? -- Scott Dial [EMAIL PROTECTED] [EMAIL PROTECTED]

Re: [Python-Dev] bug or a feature?

2008-06-10 Thread Maciej Fijalkowski
On Wed, Jun 11, 2008 at 3:36 AM, Scott Dial [EMAIL PROTECTED] wrote: Maciej Fijalkowski wrote: What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. I apologize for my ignorance, but who? Could you please cite something reputable that relies on

Re: [Python-Dev] bug or a feature?

2008-06-10 Thread Benjamin Peterson
On Tue, Jun 10, 2008 at 8:37 PM, Maciej Fijalkowski [EMAIL PROTECTED] wrote: On Wed, Jun 11, 2008 at 3:36 AM, Scott Dial I apologize for my ignorance, but who? Could you please cite something reputable that relies on this detail? It's in tests of sqlalchemy. My question is among the lines

Re: [Python-Dev] bug or a feature?

2008-06-10 Thread Raymond Hettinger
What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. Do we consider it part of python language? (Note that you cannot do the same with getattr/setattr which checks if argument is a string) Seems like a bug to me, but I don't think there is much we

Re: [Python-Dev] bug or a feature?

2008-06-10 Thread Benjamin Peterson
On Tue, Jun 10, 2008 at 9:18 PM, Raymond Hettinger [EMAIL PROTECTED] wrote: I see no reason to invent a new custom dict to prevent people from doing something they find to be useful. If you can't segfault with it, who cares. Don't worry; I'm not suggesting it. -- Cheers, Benjamin Peterson

Re: [Python-Dev] bug or a feature?

2008-06-10 Thread Greg Ewing
Maciej Fijalkowski wrote: What do you think about this code: class A: locals()[42] = 98 Seems people rely on it working. Do we consider it part of python language? Modifying the dict returned by locals() is documented as NOT being guaranteed to work, isn't it? -- Greg