Subclassing tuple and introspection

Joseph L. Casale jcasale at activenetwerx.com
Wed Dec 2 18:55:09 EST 2015


> If you're not already familiar with collections.namedtuple, have a
> look at it, as it sounds like just naming the fields may be all that
> you need. You can also subclass it further to add methods if desired.

Yeah, all the types in these collections are named tuples... The collection
itself isn't applicable, think of a simple list/tuple.

> I think that's going to depend heavily on the specific IDE being used,
> but for general usage you might consider using PEP 484 type
> annotations; I know that at least PyCharm supports their use for type
> hinting.

The guys here use PyCharm, where it becomes less than describable is
I have to make a distinct instance of the subclass for each use by each
namedtuple instance and generate doc strings that return those types
for the helper methods.

This is auto XSLT auto generated code, so I am not worried about the
overhead maintaining it, I just didn't want to have to do that if there
was a way to prime the type hinting by "properly" subclassing tuple
for example.

Thanks for the feedback.
jlc



More information about the Python-list mailing list