Subclassing tuple and introspection

Joseph L. Casale jcasale at activenetwerx.com
Wed Dec 2 18:32:31 EST 2015


I need to return a collection of various types, since python doesn't
have the terse facility of extension methods like C#, subclassing tuple
and adding a method seems like a terse way to accommodate this.

However, if the method returns one element of the collection, how can
one enable introspection for users of IDE's that the resulting reference
is of type A, and therefor has A's fields?

For example:
col = (Class(..), Class(...))
item = col[0]

Introspection will now enumerate item as an instance of Class, providing
its fields. The subclass of tuple breaks this. 

Is there a better way to do this?

Thanks,
jlc



More information about the Python-list mailing list