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.

Author _savage
Recipients Samuel Isaacson, _savage, doko, eric.snow, larry, nchammas, python-dev, rhettinger, veky
Date 2015-12-27.04:29:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1451190553.53.0.257733750054.issue24931@psf.upfronthosting.co.za>
In-reply-to
Content
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!
History
Date User Action Args
2015-12-27 04:29:13_savagesetrecipients: + _savage, rhettinger, doko, larry, python-dev, eric.snow, veky, nchammas, Samuel Isaacson
2015-12-27 04:29:13_savagesetmessageid: <1451190553.53.0.257733750054.issue24931@psf.upfronthosting.co.za>
2015-12-27 04:29:13_savagelinkissue24931 messages
2015-12-27 04:29:12_savagecreate