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


Groups > comp.lang.python > #84531

Re: Delegation in Python

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; 'transform': 0.07; 'method,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; '(say': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hmm.': 0.16; 'wrote:': 0.18; 'value.': 0.19; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'fraction': 0.24; 'passes': 0.24; 'skip': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '25,': 0.31; 'option.': 0.31; 'class': 0.32; 'brian': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'doing': 0.36; 'next': 0.36; 'effort': 0.37; 'easiest': 0.38; 'rather': 0.38; "you're": 0.61; 'more': 0.64; 'here': 0.66; '2015': 0.84; 'delegation': 0.84; 'thing,': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Yllrl8IevB3NUSXXfg2z0eiKwEHKCeTSs8aAbzssg1E=; b=LY8ERx0ln0sNlNx5el6818bWWMj5cW8l7uYUj5cUqctbGY/TZblpJ44RmtsIazG+JL XDJlKa1ohFUInRf2cVBEowiDYkZnJ9IpE7wz6NwGh5eI0ghhLu2rPxDLFbhr88LxhT37 Oq8qxpq2/OLJfLxxtyuaDPQoou32YbQ6UzFCGClE9ESs0qDhJx2xQS4dhlKCoZTa5vab VyI862EyCgsvKpr7zPb/GfdHK8p5aa65Gif/0mGMW8hF0r4midzSThC0ABur3lSg/YUA bR8zd8EOahTnUmjoz5vgVqIJmqsQX8A3A2Rn2I9kCU6IeYP40STJHnmxopTJsCU7D/Fb WFOg==
MIME-Version 1.0
X-Received by 10.107.14.131 with SMTP id 125mr10733944ioo.53.1422145714298; Sat, 24 Jan 2015 16:28:34 -0800 (PST)
In-Reply-To <K8KdncuoKPL1q1nJnZ2dnUVZ8h2dnZ2d@brightview.co.uk>
References <FeCdnXdsTpunvlnJnZ2dnUVZ8judnZ2d@brightview.co.uk> <mailman.18106.1422141738.18130.python-list@python.org> <5ZKdnd6rbdZ3sVnJnZ2dnUVZ8mCdnZ2d@brightview.co.uk> <mailman.18109.1422143020.18130.python-list@python.org> <K8KdncuoKPL1q1nJnZ2dnUVZ8h2dnZ2d@brightview.co.uk>
Date Sun, 25 Jan 2015 11:28:34 +1100
Subject Re: Delegation in Python
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.18116.1422145722.18130.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1422145722 news.xs4all.nl 2941 [2001:888:2000:d::a6]:46896
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:84531

Show key headers only | View raw


On Sun, Jan 25, 2015 at 11:18 AM, Brian Gladman <noone@nowhere.net> wrote:
> Is there a way of doing delegation rather than sub-classing?
>
> That is, can I create a class (say RF) that passes some of its methods
> to Fraction for implementation but always returns an RF?

Hmm. The key here is that you want more than just delegation; you want
to transform every return value. That's not going to be easy. It would
be easiest and cleanest to skip the whole thing, and have a separate
function for what you're doing here - not a method, a stand-alone
function.

def is_integer(fr):
    return fr.numerator % fr.denominator == 0

Next best would be the monkey-patching option. Delegation with
transformation is a lot of effort for what you want.

ChrisA

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


Thread

Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 22:57 +0000
  Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 10:22 +1100
    Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:38 +0000
      Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 10:43 +1100
        Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 00:18 +0000
          Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 11:28 +1100
            Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 07:49 +0000
              Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 19:07 +1100
      Re: Delegation in Python Gary Herron <gherron@digipen.edu> - 2015-01-24 15:47 -0800
        Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:58 +0000
  Re: Delegation in Python Gary Herron <gherron@digipen.edu> - 2015-01-24 15:41 -0800
    Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-24 23:52 +0000
  Re: Delegation in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-24 23:59 +0000
  Re: Delegation in Python Chris Angelico <rosuav@gmail.com> - 2015-01-25 11:07 +1100
  Re: Delegation in Python Terry Reedy <tjreedy@udel.edu> - 2015-01-24 20:31 -0500
    Re: Delegation in Python Brian Gladman <noone@nowhere.net> - 2015-01-25 07:43 +0000

csiph-web