Jens Troeger added the comment:

With my update from Python 3.4.3 to Python 3.4.4 (default, Dec 25 2015, 
06:14:41) I started experiencing crashes of my applications and I suspect this 
change is the culprit.

I have a class that inherits from namedtuple, and code calls vars() (i.e. 
retrieve __dict__) to iterate over an instance's attributes. Much like Raymond 
points out in http://bugs.python.org/msg249100

For example with 3.4.3:

>>> from collections import namedtuple
>>> Point = namedtuple('Point', ['x', 'y'])
>>> p = Point(1,2)
>>> p
Point(x=1, y=2)
>>> p.__dict__
OrderedDict([('x', 1), ('y', 2)])
>>> vars(p)
OrderedDict([('x', 1), ('y', 2)])

After the most recent update this breaks with 3.4.4:

>>> from collections import namedtuple
>>> Point = namedtuple('Point', ['x', 'y'])
>>> p = Point(1,2)
>>> p
Point(x=1, y=2)
>>> p.__dict__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Point' object has no attribute '__dict__'
>>> vars(p)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: vars() argument must have __dict__ attribute

I am not sure about the fix on my side. Should I use _asdict() instead of 
vars() although I would argue that vars() should remain functional across this 
change.  Calling _asdict() seems messy to me, but it works:

>>> p._asdict()
OrderedDict([('x', 1), ('y', 2)])

Why not keep the __dict__ property in tact?

  @property
  def __dict__(self):
      return self._asdict()

Thanks!

----------
nosy: +_savage

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24931>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to