This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Bug assigning list comprehension to __slots__ in python 2.5
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: fdesloges, georg.brandl
Priority: normal Keywords:

Created on 2007-06-18 14:32 by fdesloges, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg32359 - (view) Author: Fran�ois Desloges (fdesloges) Date: 2007-06-18 14:32
I use the package 2.5-4.1mdv2007.1.i586 in mandriva.
I don't know if this has already been reported elsewhere but the following code:

  a= ['C','D']
  class A(object):
    __slots__ = a + ['__'+name for name in a]
    def __init(self, c, d):
      self.__C = c
      self.__D = d
    C = property(lambda self: self.__C)
    D = property(lambda self: self.__D)
  a = A()

results is an a.name attribute with value 'D'.

But using :

  b= tuple('C','D')
  class B(object):
    __slots__ = b + tuple('__'+name for name in b)
    def __init(self, c, d):
      self.__C = c
      self.__D = d
    C = property(lambda self: self.__C)
    D = property(lambda self: self.__D)
  b = B()

b appropriately do not have a b.name attribute.
msg32360 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-06-18 15:20
Sorry, I can't follow you. Why should b have a "name" attribute?

Also, is it intentional that your __init is not named __init__?
msg32361 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-06-18 15:21
Ah, strike my last comment.

This is not a bug, or at least not fixable, since list comprehensions do leak their iteration
variable into the enclosing scope, while generator expressions don't.

They will stop doing this in Py3k.
History
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45104
2007-06-18 14:32:28fdeslogescreate