Issue33947
Created on 2018-06-23 12:58 by eric.smith, last changed 2018-10-19 17:29 by eric.smith. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 9916 | merged | thatiparthy, 2018-10-16 19:08 | |
| PR 9970 | merged | miss-islington, 2018-10-19 16:55 | |
| Messages (5) | |||
|---|---|---|---|
| msg320305 - (view) | Author: Eric V. Smith (eric.smith) * | Date: 2018-06-23 12:58 | |
>>> @dataclass ... class C: ... f: "C" ... >>> c = C(None) >>> c.f = c >>> c Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 2, in __repr__ File "<string>", line 2, in __repr__ File "<string>", line 2, in __repr__ [Previous line repeated 328 more times] RecursionError: maximum recursion depth exceeded >>> It would be better to produce "C(f=...)". |
|||
| msg320322 - (view) | Author: Rémi Lapeyre (remi.lapeyre) * | Date: 2018-06-23 19:13 | |
This seems like a difficult problem to tackle in all cases, if two dataclasses reference each other the cycle could be complex to identify and introduce complexity. The way repr is defined is part of PEP 557 and actually force this behavior. Should the `repr` parameter default to False or not include the repr of each field? |
|||
| msg320327 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2018-06-23 19:29 | |
We have a tool designed for this problem. See: https://docs.python.org/3/library/reprlib.html#reprlib.recursive_repr If you want to avoid a dependency, it is easy to inline the logic. For an example, see the Python 2.7 version of collections.OrderedDict.__repr__. |
|||
| msg320331 - (view) | Author: Eric V. Smith (eric.smith) * | Date: 2018-06-23 20:15 | |
Thanks, Raymond. I'm working on a patch. |
|||
| msg328055 - (view) | Author: Eric V. Smith (eric.smith) * | Date: 2018-10-19 17:28 | |
New changeset b9182aa7dad8991fc8768ae494b45b5f7c316aca by Eric V. Smith (Miss Islington (bot)) in branch '3.7': bpo-33947: dataclasses no longer can raise RecursionError in repr (GF9916) (#9970) https://github.com/python/cpython/commit/b9182aa7dad8991fc8768ae494b45b5f7c316aca |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2018-10-19 17:29:46 | eric.smith | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2018-10-19 17:28:35 | eric.smith | set | messages: + msg328055 |
| 2018-10-19 16:55:05 | miss-islington | set | pull_requests: + pull_request9315 |
| 2018-10-16 19:08:05 | thatiparthy | set | keywords:
+ patch stage: patch review pull_requests: + pull_request9273 |
| 2018-10-01 10:58:19 | eric.smith | set | assignee: eric.smith |
| 2018-09-23 14:47:24 | xtreak | set | nosy:
+ xtreak |
| 2018-06-23 20:15:00 | eric.smith | set | messages:
+ msg320331 versions: + Python 3.8 |
| 2018-06-23 19:29:13 | rhettinger | set | priority: low -> normal nosy: + rhettinger messages: + msg320327 |
| 2018-06-23 19:13:22 | remi.lapeyre | set | nosy:
+ remi.lapeyre messages: + msg320322 |
| 2018-06-23 12:58:46 | eric.smith | create | |