Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108619
| 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 | Fri, 13 May 2016 20:33:11 +0000 |
| Lines | 31 |
| Message-ID | <mailman.647.1463171609.32212.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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de vQW3u/RRbS4rhkKTzy2wcARfEqnICF3wL7vb3/YDqt4g== |
| 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.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'api': 0.09; 'derived': 0.09; 'python': 0.10; 'def': 0.13; 'explicitly': 0.15; 'languages.': 0.15; 'subject: \n ': 0.15; '(more': 0.16; '2016': 0.16; 'alarm': 0.16; 'cls': 0.16; 'gregory': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'registry': 0.16; 'skip:@ 20': 0.16; 'subject:user': 0.16; 'wrote:': 0.16; 'string': 0.17; '>': 0.18; 'input': 0.18; 'to:2**1': 0.21; 'decorator': 0.22; 'sets': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'defining': 0.27; 'function': 0.28; 'idea': 0.28; '13,': 0.29; 'subject:that': 0.29; 'raise': 0.29; "i'm": 0.30; 'classes': 0.30; 'probably': 0.31; 'statement': 0.32; 'class': 0.33; 'picking': 0.33; 'similar': 0.33; 'add': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'c++': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'received:209': 0.38; 'received:209.85.220': 0.38; 'why': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'share': 0.61; 'making': 0.62; 'more': 0.63; 'great': 0.63; 'hear': 0.64; 'subject:Design': 0.79; 'bells': 0.84 |
| 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=1ojfi6s77uxKQm6N1tqPwcHC+AkYKcd7Z3/kQGD45V8=; b=tjQvrO1IhvmSeKp2xRl6rjnGM7XU4MMeLzBpMStTH94A43WoXREdlaFmeq+VyMIHQY +heEotiiHwjjlW+D37s1IXoqEs+j58r8t5lXtbg5dsC9o25U1lzcQ6LYQM0HOqCI3uqn Tq9s3ZFRY1G3WHr/OJiKN0jd32pm7gywL3eVYMxAblW0LLO/DePpmjtTKx2QGRK2AVPL KgNaFy1kyZ6GifiM0/oeTPOlHlbzrCN7+FTk9qA4mNTze9qXatDhZutjHu1nPs506I2V OzCk79P6uIz5UTWrTf6vXk4EML3erQs4+vplPw13e0irqPwenTFRIGIfAeEFIqsBCUt6 B8cw== |
| 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=1ojfi6s77uxKQm6N1tqPwcHC+AkYKcd7Z3/kQGD45V8=; b=J+Yf3HWHOufrUK7IrzrJ/IebR4RDYfVYAZ7nVus5J0mAIrFKyeWzTJFJoGwGORM6Wm pHusLHup/EBhODTIcHGBHw6ezMg8Z/Uqqc7q9EGHIfM4N9wb5zefrnG/7iHfVE1R7sqU GQvQO062fFMh9uLm7qA6R2MjNpa2zVy9DRZrZlgTP5OqVI8NRZbvjj9+AjNNiUxOX0G9 ovlKAj5LscXVQIhIorCFzvWlNCzZRtVofXU0THQPRmTAPCHOOUH8olMfxqWKEU8HXnQW DE3AkmaqAODjck7VwRZh0R+oQb+xmjIjAR+9hSBOFjHzwJypEQm2e+EXI3OLvNi1IUlD VIHw== |
| X-Gm-Message-State | AOPr4FWQYRN9OLv78yVJOlIfuY6wEpxSyogyBLSo//6Vr8q+Xgh0rGwMFgIppoELycwSjnbTzeToXu97HmCylA== |
| X-Received | by 10.55.15.102 with SMTP id z99mr13502940qkg.209.1463171601335; Fri, 13 May 2016 13:33:21 -0700 (PDT) |
| In-Reply-To | <dplassFelugU1@mid.individual.net> |
| 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 | <CAGgTfkPeqybAeqXLq8FHyRSb+d8KLemvxLrk8i3PfbWdwV4rBA@mail.gmail.com> |
| X-Mailman-Original-References | <5734ECDF.7070006@gmx.de> <mailman.617.1463087060.32212.python-list@python.org> <dplassFelugU1@mid.individual.net> |
| Xref | csiph.com comp.lang.python:108619 |
Show key headers only | View raw
On Fri, May 13, 2016 at 2:41 AM Gregory Ewing <greg.ewing@canterbury.ac.nz>
wrote:
> Dirk Bächle wrote:
> > I'm currently following the "Factory" pattern (more or less) as I know
> > it from C++ and similar languages.
>
> This statement sets off alarm bells for me. If you're using some
> design pattern in Python just because you learned to do it that
> way in C++/Java/whatever, you're probably making it more
> complicated than it needs to be.
>
I share Greg's trepidation when I hear a phrase like that, but the general
idea of a registry of classes or functions and then picking the right one
based on string input is fine.
How would the API work for custom Taskmasters? 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?
def register(key):
def decorator(cls):
if not issubclass(cls, Taskmaster):
raise TypeError('You fool!')
registry[key] = cls
return decorator
@register('noclean')
class NoCleanTaskMaster(TaskMaster):
"Looks clean enough, why worry?"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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