Neil Girdhar <mistersh...@gmail.com> 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 isinstance(x, Sequence) and isinstance(x, Mapping).  The 
advantage to this is flexibility with user-defined types.

The problem seems to be that the abstract base classes don't promise anything 
about the constructor.  It seems like some Sequence types accept an Iterable 
(e.g. tuple), but others like NamedTuple want positional arguments.  I think 
this promise should be encoded in some way.

Maybe a third solution is to have NamedTuple special-cased out:

isinstance(x, Sequence) and not isinstance(x, NamedTuple)

If there are other Sequence types that do this (are there?) then an abstract 
base class could be created.

This solution has the benefit of playing the most nicely with user-defined 
classes.

----------
nosy: +NeilGirdhar

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

Reply via email to