Re: [Python-Dev] Avoiding error from repr() of recursive dictview
Hi Greg, Thanks for the feedback. On 22 July 2013 23:01, Gregory P. Smith wrote: > On Mon, Jul 22, 2013 at 2:44 PM, Ben North wrote: >> [... proposed change of behaviour such that a recursive >> dictview gives a repr() with "..." rather than a RuntimeError ...] > > [...] Post it on an issue on bugs.python.org. http://bugs.python.org/issue18533 Ben. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Avoiding error from repr() of recursive dictview
23.07.2013 00:01, Gregory P. Smith wrote: On Mon, Jul 22, 2013 at 2:44 PM, Ben North wrote: A friend of mine, Ruadhan O'Flanagan, came across a bug which turned out to be the one noted in [http://bugs.python.org/issue18019 [1]], i.e.: >>> d={} >>> d[42]=d.viewvalues() >>> d This issue has been fixed in hg; the behaviour now is that a RuntimeError is produced for a recursive dictionary view: >>> d={} >>> d[42]=d.viewvalues() >>> d # (output line-broken:) {42: Traceback (most recent call last): File "", line 1, in RuntimeError: maximum recursion depth exceeded while getting the repr of a list Before finding this, though, I'd investigated and made a patch which produces a similar "..." output to a recursive dictionary. Reworking against current 2.7, the behaviour would be: >>> x={} >>> x[42]=x >>> x # existing behaviour for dictionaries: {42: {...}} >>> d={} >>> d[42]=d.viewvalues() >>> d # new behaviour: {42: dict_values([...])} >>> d[43]=d.viewitems() >>> d # (output line-broken:) {42: dict_values([..., dict_items([(42, ...), (43, ...)])]), 43: dict_items([(42, dict_values([..., ...])), (43, ...)])} Attached is the patch, against current 2.7 branch. If there is interest in applying this, I will create a proper patch (changelog entry, fix to Lib/test/test_dictviews.py, etc.). Mailing lists are where patches go to get lost and die. :) Post it on an issue on bugs.python.org [4]. Given that the RuntimeError fix has been released, your proposed ... behavior is arguably a new feature so I'd only expect this to make sense for consideration in 3.4, not 2.7. (if accepted at all) IMHO it's still a bug (even though not so painful as segfault) that should also be fixed in 2.7 and 3.2/3.3. In other cases (such as `d={}; d[42]=d; repr(d)`) Python does its best to avoid an error -- why in this case (`d={}; d[42]=d.values(); repr(d)`) should it raise an exception? IMHO it's an obvious oversight in implementation, not a feature that anybody would expect. Regards. *j ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Avoiding error from repr() of recursive dictview
On Mon, Jul 22, 2013 at 2:44 PM, Ben North wrote: > Hi, > > A friend of mine, Ruadhan O'Flanagan, came across a bug which turned out > to be the one noted in [http://bugs.python.org/issue18019], i.e.: > > >>> d={} > >>> d[42]=d.viewvalues() > >>> d > > > This issue has been fixed in hg; the behaviour now is that a > RuntimeError is produced for a recursive dictionary view: > > >>> d={} > >>> d[42]=d.viewvalues() > >>> d # (output line-broken:) > {42: Traceback (most recent call last): > File "", line 1, in > RuntimeError: maximum recursion depth exceeded > while getting the repr of a list > > Before finding this, though, I'd investigated and made a patch which > produces a similar "..." output to a recursive dictionary. Reworking > against current 2.7, the behaviour would be: > > >>> x={} > >>> x[42]=x > >>> x # existing behaviour for dictionaries: > {42: {...}} > > >>> d={} > >>> d[42]=d.viewvalues() > >>> d # new behaviour: > {42: dict_values([...])} > >>> d[43]=d.viewitems() > >>> d # (output line-broken:) > {42: dict_values([..., dict_items([(42, ...), (43, ...)])]), > 43: dict_items([(42, dict_values([..., ...])), (43, ...)])} > > Attached is the patch, against current 2.7 branch. If there is interest > in applying this, I will create a proper patch (changelog entry, fix to > Lib/test/test_dictviews.py, etc.). > Mailing lists are where patches go to get lost and die. :) Post it on an issue on bugs.python.org. Given that the RuntimeError fix has been released, your proposed ... behavior is arguably a new feature so I'd only expect this to make sense for consideration in 3.4, not 2.7. (if accepted at all) -gps > > Thanks, > > Ben. > > ___ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/greg%40krypto.org > > ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com