[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-09-16 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: > [..] but I think it's the best we can do. It's consistent with any other > class derived from tuple or list: [...] I agree with this argument. Sorry for delay with my response and thank you Eric for taking care about this issue! --

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-09-14 Thread Eric V. Smith
Change by Eric V. Smith : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-09-14 Thread Eric V. Smith
Eric V. Smith added the comment: New changeset 78aa3d8f5204bc856d7b2eb67288cf90c6a30660 by Eric V. Smith (Miss Islington (bot)) in branch '3.7': bpo-34363: dataclasses.asdict() and .astuple() now handle fields which are namedtuples. (GH-9151) (GH-9304)

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-09-14 Thread miss-islington
Change by miss-islington : -- pull_requests: +8733 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-09-14 Thread Eric V. Smith
Eric V. Smith added the comment: New changeset 9b9d97dd139a799d28ff8bc90d118b1cac190b03 by Eric V. Smith in branch 'master': bpo-34363: dataclasses.asdict() and .astuple() now handle fields which are namedtuples. (GH-9151)

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-09-11 Thread Eric V. Smith
Eric V. Smith added the comment: The question here is: what should asdict() return if the dataclass contains a namedtuple? What the code is trying to do (but currently failing!) is to return another namedtuple, but with the values returned by recursively calling in to asdict() (or rather,

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-09-10 Thread Eric V. Smith
Eric V. Smith added the comment: I like GH-9151 better because it changes only the namedtuple case, not other classes that are derived from list or tuple. But, I might copy some of the tests from 9151 before I'm done with this. -- ___ Python

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-09-10 Thread Eric V. Smith
Change by Eric V. Smith : -- pull_requests: +8598 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-10 Thread Eric V. Smith
Eric V. Smith added the comment: For the record, I don't disagree with namedtuples not having a base class. Maybe it's best to let copy.deepcopy() deal with namedtuples, instead of trying to detect them here. So just special case exact tuples and lists, and pass everything else to

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-10 Thread Neil Girdhar
Neil Girdhar added the comment: > The code generated by oollections.namedtuple was based on patterns already in > widespread use at the time. That's fair enough. However, it seems like there is one important difference: unlike any other Sequence, namedtuples cannot be initialized with an

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-10 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Raymond has resisted adding a base class to namedtuple. I believe the > preferred way to identify a namedtuple is to look for a _fields member. FWIW, that was also Guido's opinion as well. A named tuple is generic concept defined in the glossary as

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-10 Thread Eric V. Smith
Eric V. Smith added the comment: Hmm, for some reason I'm not getting mail from this issue, so I made my PR before I saw the comments since my last comment. Raymond has resisted adding a base class to namedtuple. I believe the preferred way to identify a namedtuple is to look for a _fields

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-10 Thread Eric V. Smith
Change by Eric V. Smith : -- keywords: +patch pull_requests: +8212 stage: -> patch review ___ Python tracker ___ ___

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-10 Thread Neil Girdhar
Neil Girdhar added the comment: Why can't we add an ABC into a NamedTuple instance's MRO? Because while I like Eric's solution, it seems to be backwards: tuple and list are not the special cases—NamedTuple is. All sequences accept an iterable in their constructor, and NamedTuple doesn't.

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-10 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: Eric, I like your solution. It is probably not perfect, but at least it solves the existing problem without introducing obvious problems. Neil, your way will not work since named tuples don't have NamedTuple in their MROs: CustomNT.mro == (CustomNT,

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-09 Thread Neil Girdhar
Neil Girdhar added the comment: Sorry if I'm intruding here, but I really dislike that we are doing isinstance versus list, tuple, and dict. And I dislike even more type(x) in (list, tuple). I think the ideal thing to do would have been to check versus abstract base classes like

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-09 Thread Eric V. Smith
Eric V. Smith added the comment: Maybe do both, then. Also, it's probably better for performance reasons (I know: premature optimization and all that ...): @@ -1018,8 +1018,10 @@ def _asdict_inner(obj, dict_factory): value = _asdict_inner(getattr(obj, f.name), dict_factory)

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-09 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: The problem with this solution is that it may brea (relatively common) use case of tuple valued fields, e.g.: >>> tuple(*[x for x in a]) Traceback (most recent call last): File "", line 1, in TypeError: tuple expected at most 1 arguments, got 2

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-08 Thread Eric V. Smith
Eric V. Smith added the comment: Thanks for the pointer, Ivan. I haven't really thought it through yet, but this fixes the problem at hand: diff --git a/dataclasses.py b/dataclasses.py index ba34f6b..54916ee 100644 --- a/dataclasses.py +++ b/dataclasses.py @@ -1019,7 +1019,7 @@ def

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-08 Thread Eric V. Smith
Eric V. Smith added the comment: Oops, didn't see that you commented on this, Ivan. I'll do some analysis tomorrow. -- ___ Python tracker ___

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-08 Thread Eric V. Smith
Change by Eric V. Smith : -- assignee: -> eric.smith components: +Library (Lib) -Interpreter Core versions: +Python 3.8 ___ Python tracker ___

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-08 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: OK, so the crux of the bug is this difference: >>> a = (1, 2) >>> tuple(x for x in a) (1, 2) >>> NamedTupleAttribute(x for x in a) NamedTupleAttribute(example= at 0x10e2e52a0>) A potential solution would be to either use `type(obj) in (list, tuple)`

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-08 Thread Ivan Levkivskyi
Change by Ivan Levkivskyi : -- nosy: +levkivskyi ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-08 Thread Eric V. Smith
Change by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue34363] dataclasses.asdict() mishandles dataclass instance attributes that are instances of subclassed typing.NamedTuple

2018-08-08 Thread Alex DeLorenzo
New submission from Alex DeLorenzo : Example: from typing import NamedTuple from dataclasses import dataclass, asdict class NamedTupleAttribute(NamedTuple): example: bool = True @dataclass class Data: attr1: bool attr2: NamedTupleAttribute data = Data(True,