[issue7796] No way to find out if an object is an instance of a namedtuple

2014-01-12 Thread Andrew Barnert
Andrew Barnert added the comment: I believe the structseq issues are a lot easier to solve than the appear. See #20230, which adds a _fields member to every structseq type. Having done that, a NamedTuple ABC works on them just fine. And of course duck typing them without an ABC does too.

[issue7796] No way to find out if an object is an instance of a namedtuple

2013-06-25 Thread Eric Snow
Eric Snow added the comment: A NamedTuple ABC doesn't have to define any API (so that part could wait?)[1]. I see it as most useful for isinstance checks. Here's a solution along those lines: class NamedTuple(Sequence): @classmethod def __subclasshook__(cls, C): if cls is

[issue7796] No way to find out if an object is an instance of a namedtuple

2013-06-08 Thread Eric Snow
Changes by Eric Snow ericsnowcurren...@gmail.com: -- nosy: +eric.snow ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7796 ___ ___ Python-bugs-list

[issue7796] No way to find out if an object is an instance of a namedtuple

2013-06-08 Thread Eric Snow
Eric Snow added the comment: It may not enough, but the use of namedtuples (vs. plain tuples) with functools.singledispatch() would be messier without a NamedTuple ABC (or other base type). Of course, when would you want to dispatch specifically on namedtuple? I can think of a few

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-04-20 Thread Raymond Hettinger
Raymond Hettinger raymond.hettin...@gmail.com added the comment: Detecting _fields is the simplest thing we can do right now. There are too many structseq API differences to warrant bringing them under a single ABC umbrella. -- dependencies: -Enhance Object/structseq.c to match

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-31 Thread Jan Kaliszewski
Jan Kaliszewski z...@chopin.edu.pl added the comment: PS. For the record: the final recipe is here: http://code.activestate.com/recipes/577629-namedtupleabc-abstract-base-class-mix-in-for-named/ -- ___ Python tracker rep...@bugs.python.org

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-31 Thread Roundup Robot
Roundup Robot devnull@devnull added the comment: New changeset 7aa3f1f7ac94 by Raymond Hettinger in branch '3.2': Issue #7796: Add link to Jan Kaliszewski's alternate constructor and ABC for named tuples. http://hg.python.org/cpython/rev/7aa3f1f7ac94 New changeset 330d3482cad8 by Raymond

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-28 Thread Jan Kaliszewski
Jan Kaliszewski z...@chopin.edu.pl added the comment: Thank you. Raymond is against the idea so I don't know if it makes sense to create the real patch for now (it would patch the collections module and, I suppose, addming tests, docs etc.). Anyway, if somebody would be interested in the

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-28 Thread Santoso Wijaya
Changes by Santoso Wijaya santoso.wij...@gmail.com: -- nosy: +santa4nt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7796 ___ ___ Python-bugs-list

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-28 Thread Sridhar Ratnakumar
Changes by Sridhar Ratnakumar sridh...@activestate.com: -- nosy: -srid ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7796 ___ ___

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-28 Thread Daniel Urban
Changes by Daniel Urban urban.dani...@gmail.com: -- nosy: +durban ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7796 ___ ___ Python-bugs-list

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-27 Thread Jan Kaliszewski
Jan Kaliszewski z...@chopin.edu.pl added the comment: On python-ideas I have proposed an ABC being also a kind of a mix-in, potentially making namedtuple subclassing (with custom methods etc.) more convenient, e.g.: class MyRecord(namedtuple.abc): _fields = 'x y z' def

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-27 Thread Jan Kaliszewski
Jan Kaliszewski z...@chopin.edu.pl added the comment: PS. Newer, shorter version: http://dpaste.org/2aiQ/ -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7796 ___

[issue7796] No way to find out if an object is an instance of a namedtuple

2011-03-27 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: Thanks for working on this. I have some remarks: 1) Please post diff files here instead of using external sites. See http://docs.python.org/devguide/patch#preparation 2) The license you chose doesn’t allow the PSF to include it into Python,

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-11-27 Thread Éric Araujo
Changes by Éric Araujo mer...@netwok.org: -- dependencies: +Enhance Object/structseq.c to match namedtuple and tuple api ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7796 ___

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-09-02 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: To make sure I understand: StructSeq is the C-pendent of named tuples, and a NamedTuple ABC would have to work with StructSeqs too? -- ___ Python tracker rep...@bugs.python.org

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-09-01 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Am deferring this to Py3.3. There is a workaround available just using duck-typing and I would like to wait until more more has been done on StructSeq before setting committing to an new namedtuple Abstract Base Class (one

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-08-07 Thread Raymond Hettinger
Changes by Raymond Hettinger rhettin...@users.sourceforge.net: -- priority: normal - high ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7796 ___

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-02-22 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Discussed this with GvR. Here's a recap: For 2.6 and 3.1 which are already released, check for the _fields attribute. This is a guaranteed part of the API is not fragile. For the C structures, check for the n_fields

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-29 Thread Sridhar Ratnakumar
Sridhar Ratnakumar sridh...@activestate.com added the comment: For more discussion on this, see http://stackoverflow.com/questions/2166818 -- components: +Library (Lib) nosy: +srid ___ Python tracker rep...@bugs.python.org

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread Peter Waller
New submission from Peter Waller peter.wal...@gmail.com: Apologies if there is a way of doing this, but I haven't been able to find anything. I need to be able to do the following: my_tuple = namedtuple(my_tuple, a b c) obj = my_tuple(1,2,3) if isinstance(obj, namedtuple): .. do stuff ..

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: In this case, what is wrong with: if isinstance(obj, my_tuple): ... or do you want to catch all namedtuples? And if so, why? (I suppose it would be easy to make all namedtuples inherit from a common base class, though) -- assignee: -

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: Hello namedtuple is a factory function, not a class (as hinted by the naming in lower case, see PEP 8), so there are no instances of namedtuple. You can workaround that with issubclass, or checking for special namedtuples attributes (_asdict,

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread Peter Waller
Peter Waller peter.wal...@gmail.com added the comment: Hi Antoine and Eric, Thanks for your responses. I need to be able to catch all named tuples, I don't know in advance what instance of a namedtuple it might be, but I want my function to only accept named tuples. Is this unreasonable?

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: I need to be able to catch all named tuples, I don't know in advance what instance of a namedtuple it might be, but I want my function to only accept named tuples. Is this unreasonable? I don't know. Why exactly don't you want to accept

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread Peter Waller
Peter Waller peter.wal...@gmail.com added the comment: In this case, I need to have names for each object. It is also desirable to use the namedtuple because of their lightweight nature. If they were to subclass the namedtuple I would be happy to accept that, but I really do want them to pass

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread betatim
Changes by betatim beta...@gmail.com: -- nosy: +thead ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7796 ___ ___ Python-bugs-list mailing list

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: It seems a perfect case for duck typing style of programming: All namedtuple classes: - inherit from tuple - have a _fields class attribute These two properties could be the duck test for namedtuples, regardless of the actual

[issue7796] No way to find out if an object is an instance of a namedtuple

2010-01-27 Thread Peter Waller
Peter Waller peter.wal...@gmail.com added the comment: Hi Amaury, Thanks. I had heard of but never bothered to read about duck-typing before now; though I have used it passively before. I think it does make sense in this case. I can't imagine any case where checking for the _fields attribute