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


Groups > comp.lang.python > #108748

Re: Design: Idiom for classes and methods that are customizable by the user?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: Design: Idiom for classes and methods that are customizable by the user?
Date Tue, 17 May 2016 18:13:06 +0000
Lines 34
Message-ID <mailman.65.1463508799.19823.python-list@python.org> (permalink)
References <5734ECDF.7070006@gmx.de> <mailman.617.1463087060.32212.python-list@python.org> <dplassFelugU1@mid.individual.net> <CAGgTfkPeqybAeqXLq8FHyRSb+d8KLemvxLrk8i3PfbWdwV4rBA@mail.gmail.com> <573B300A.5080502@gmx.de> <CAGgTfkPoPxzarh3uazCW0x6ZPwM1wamVDZm8r5h7++8xJkG5pg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de 9j3lBGlcYfzpxfOtTQNXJQSK2O5ewYYuNpLR5s8LGjHg==
Return-Path <michael.selik@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'api': 0.09; 'beginners': 0.09; 'defined.': 0.09; 'derived': 0.09; 'subclass': 0.09; 'url:pocoo': 0.09; 'python': 0.10; 'python.': 0.11; 'url:)': 0.14; 'explicitly': 0.15; 'subject: \n ': 0.15; '"@"': 0.16; '2016': 0.16; 'codebase,': 0.16; 'metaclass': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'some)': 0.16; 'subject:user': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'first.': 0.18; '&gt;': 0.18; 'all,': 0.20; 'to:2**1': 0.21; 'pass': 0.22; 'trying': 0.22; '(or': 0.23; 'header:In-Reply-To:1': 0.24; 'discussion': 0.24; "doesn't": 0.26; 'example': 0.26; 'compare': 0.27; 'to:no real name:2**1': 0.27; 'message-id:@mail.gmail.com': 0.27; 'defining': 0.27; 'function': 0.28; 'subject:that': 0.29; 'objects': 0.29; "i'm": 0.30; 'classes': 0.30; 'that.': 0.30; "we're": 0.30; 'creating': 0.30; 'code': 0.30; 'class.': 0.30; 'probably': 0.31; 'class': 0.33; 'decorators': 0.33; 'tue,': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'c++': 0.35; 'mix': 0.35; 'knowledge': 0.35; 'but': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'framework': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'doing': 0.38; 'received:209': 0.38; 'received:209.85.220': 0.38; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; "you'll": 0.61; 'strange': 0.63; 'more': 0.63; 'great': 0.63; 'our': 0.64; 'special': 0.73; 'subject:Design': 0.79; 'average': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=8gtp1YqSSSA7/VhekOVgrwGxo2smaUlw698CqBmZyJA=; b=LNhB5E8UyOrajUp1F03T2SH30cpDPNxSKLLpB6fbDXirhldKve8ZocSSmIviMehY3f zLn887QG4XmCRnBPpfvnnH3ToqK1iVQcOb4CZh+Lf1SmHdpGTmX5bOab7HKF9ntSEaey +//atHnYftaiQhOawLIFoCKVocHUUYIn+DFxlAwVe/S9cMWfmCn7YgP0zDxvC5AV0ef4 l68zwmhwHMR91RHzlZ1ZzgCEQQTil9AsN+ShiNvuIYpRHJbrsEcrE6X/UzcCUbKJvXBt esQMw6XcUM0O8B3Nny3aZQjaBVBS+TZUDOcYyZ3lkH2KuvmF/XNbFIsKqiNrdXpe64+/ dkQA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=8gtp1YqSSSA7/VhekOVgrwGxo2smaUlw698CqBmZyJA=; b=hnEhk0sUYNpTOBcCidkAcI1afSyCcj6wMV8dsqt9OUMw2KdkFf9xtpHwmxOBTcidK7 G2++jpLqf2steHKmYp+3yWCG+hMHRDY7U0BdoomoxDTUNqtwXdENSReFfQl9SHtuaLG+ qDGPqSO+gsuUhaL5YOSXLg317O1EGNgbbX6LnzqvGRgyC72NYvxQoCuJo1iDI/R51VDj gko7WCwbeE+pyxmQVLftuN/M1mpv8UsQWBxMju2Tc7rNL8kKDb+S+sOpdI7P+BF1mxkd hD2PLZtdUmuf73qAafUGGMmOqX9tDdBXYsOVrCviS68SAwb5XcmwegOzgSQzfOwRNKKF SUBw==
X-Gm-Message-State AOPr4FUP2mh6J6+3csgAPY8FpAQYsM0qhR6wyeznIlQXldnb0NIH00RyySKvBHpYWNE9iiWOQWnbih6nvVZApA==
X-Received by 10.55.15.102 with SMTP id z99mr3217763qkg.209.1463508796242; Tue, 17 May 2016 11:13:16 -0700 (PDT)
In-Reply-To <573B300A.5080502@gmx.de>
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
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>
X-Mailman-Original-Message-ID <CAGgTfkPoPxzarh3uazCW0x6ZPwM1wamVDZm8r5h7++8xJkG5pg@mail.gmail.com>
X-Mailman-Original-References <5734ECDF.7070006@gmx.de> <mailman.617.1463087060.32212.python-list@python.org> <dplassFelugU1@mid.individual.net> <CAGgTfkPeqybAeqXLq8FHyRSb+d8KLemvxLrk8i3PfbWdwV4rBA@mail.gmail.com> <573B300A.5080502@gmx.de>
Xref csiph.com comp.lang.python:108748

Show key headers only | View raw


On Tue, May 17, 2016 at 11:18 AM Dirk Bächle <tshortik@gmx.de> wrote:

>
> > It's not so great to require
> > that the user must explicitly ``add`` their derived class after defining
> > it. Perhaps that add function could be a decorator?
>
> Our current API doesn't use decorators at all, since it's also aimed at
> people with no (or only some) knowledge of Python.


I think you'll find that users of decorators do not need any special
knowledge. The Flask framework (http://flask.pocoo.org/) is proof of that.


> decorators...would have looked strange to the average user perhaps?
>

Many beginners are willing to mimic your example code without questioning
what that "@" thingy is doing above the function or class.

Compare that with trying to explain to a C++ user that in Python classes
are actually objects and you can pass them to the ``add`` function to
register them... that's going to take a while.

We're now free to add them into the mix for our new Python 2.7.x/3.y
> codebase, but this would probably require an API discussion
> first.
>

An alternative would be creating a TaskmasterMeta metaclass that registers
the Taskmaster subclass when it's defined. I'm a little reluctant to
recommend that one. I find decorators to be more elegant.

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


Thread

Design: Idiom for classes and methods that are customizable by the user? Dirk Bächle <tshortik@gmx.de> - 2016-05-12 22:51 +0200
  Re: Design: Idiom for classes and methods that are customizable by the user? Marko Rauhamaa <marko@pacujo.net> - 2016-05-13 01:01 +0300
    Re: Design: Idiom for classes and methods that are customizable by the user? Dirk Bächle <tshortik@gmx.de> - 2016-05-13 00:42 +0200
      Re: Design: Idiom for classes and methods that are customizable by the user? Marko Rauhamaa <marko@pacujo.net> - 2016-05-13 08:53 +0300
  Re: Design: Idiom for classes and methods that are customizable by the   user? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-05-13 18:35 +1200
    Re: Design: Idiom for classes and methods that are customizable by the user? Michael Selik <michael.selik@gmail.com> - 2016-05-13 20:33 +0000
    Re: Design: Idiom for classes and methods that are customizable by the user? Dirk Bächle <tshortik@gmx.de> - 2016-05-17 16:51 +0200
    Re: Design: Idiom for classes and methods that are customizable by the user? Michael Selik <michael.selik@gmail.com> - 2016-05-17 18:13 +0000

csiph-web