Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99922

Re: Subclassing tuple and introspection

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From "Joseph L. Casale" <jcasale@activenetwerx.com>
Newsgroups comp.lang.python
Subject Re: Subclassing tuple and introspection
Date Wed, 2 Dec 2015 23:55:09 +0000
Lines 24
Message-ID <mailman.151.1449100520.14615.python-list@python.org> (permalink)
References <CALwzid=LdYAf8etvEMgrYH5OnmgqN-H-xWUUB455gBYdyd_p+A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="iso-8859-1"
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de wOvM832+uFMSjl6WxIMuEASuLOekbvutX/qL1wTdbLsg==
Return-Path <jcasale@activenetwerx.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'heavily': 0.04; 'applicable,': 0.07; 'desired.': 0.07; 'collections': 0.09; 'ide': 0.09; 'subclass': 0.09; 'tuple': 0.09; 'yeah,': 0.09; 'feedback.': 0.15; 'distinct': 0.16; 'naming': 0.16; 'received:172.18.0': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subclassing': 0.16; 'example.': 0.18; 'helper': 0.18; 'to:2**1': 0.21; 'doc': 0.22; 'subject:skip:i 10': 0.22; 'code,': 0.23; 'header:In-Reply-To:1': 0.24; 'used,': 0.27; 'least': 0.27; 'methods.': 0.29; 'pep': 0.29; 'becomes': 0.30; 'maintaining': 0.34; 'add': 0.34; 'instance': 0.35; "isn't": 0.35; 'supports': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'thanks': 0.37; 'guys': 0.38; 'itself': 0.38; "didn't": 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'collection': 0.60; 'further': 0.62; 'here': 0.66; 'prime': 0.72; 'sounds': 0.76; 'to:name:python': 0.84; 'worried': 0.84; 'xslt': 0.84
X-Authority-Analysis v=2.1 cv=AMkI9oPf c=1 sm=1 tr=0 a=g3mLq75WYuDrh3Lt0JSDww==:117 a=g3mLq75WYuDrh3Lt0JSDww==:17 a=QC7fh9NfAAAA:8 a=P90J6pEA2ccA:10 a=8nJEP1OIZ-IA:10 a=wUQvQvOEmiQA:10 a=KGwnUL8Cgo9be_8Myt4A:9 a=wPNLvfGTeEIA:10
X-Spam-Checker-Version SpamAssassin 3.4.0 (2014-02-07) on mail.activenetwerx.com
X-Spam-Level
X-Spam-Status No, score=-1.0 required=5.0 tests=ALL_TRUSTED, T_RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.0
Thread-Topic Subclassing tuple and introspection
Thread-Index AQHRLVkERwHpQKKW4EiOavIzwUIB8Z640hyA//+Ls+E=
In-Reply-To <CALwzid=LdYAf8etvEMgrYH5OnmgqN-H-xWUUB455gBYdyd_p+A@mail.gmail.com>
Accept-Language en-CA, en-US
Content-Language en-CA
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [172.18.0.4]
X-CMAE-Envelope MS4wfIFpy1J3IbJma2FNwrIya50A1BS3WBxKOnvNOrOwB959SNqPWg4lMfZmmYPSPhK9FS2/KFADjTFbi15fJ5z6Y5mw6f/uTK3EfOQNsr0NMSkwmHx75rQ1 KLEK+ngfdFBg5FDBKH/U1HfvvlNEN8WouoDvpi8LfvJdi0pH2/j1kLvSK5bnELToFf/NawaTyOH6IQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:99922

Show key headers only | View raw


> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Subclassing tuple and introspection "Joseph L. Casale" <jcasale@activenetwerx.com> - 2015-12-02 23:55 +0000

csiph-web