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


Groups > comp.lang.python > #111023

Re: Lost in descriptor land

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From eryk sun <eryksun@gmail.com>
Newsgroups comp.lang.python
Subject Re: Lost in descriptor land
Date Sun, 3 Jul 2016 23:59:09 +0000
Lines 22
Message-ID <mailman.51.1467590399.2295.python-list@python.org> (permalink)
References <b9c69ca0-a338-41ec-bfa5-b14510e2cb8f@googlegroups.com> <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> <CALwzidk9AJa0m0086_xKcYearCv34NK8xQ2Q=1SMZv7WbM2yRA@mail.gmail.com> <mailman.30.1467500855.2295.python-list@python.org> <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com> <CACL+1au7XBG7r_JgfL-bDwxfW8j9aoSDfUjFpJME9=s9Y4dHVA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de M6Qr9yiwuSKV1790O84hfwHd2RLKSGPS57NLgUo4JGaw==
Return-Path <eryksun@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'context': 0.05; 'method,': 0.07; 'method:': 0.09; '2016': 0.16; 'bind': 0.16; 'insightful': 0.16; 'instance)': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'fine': 0.28; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'ahead': 0.35; 'instance': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'self': 0.38; 'to:addr:python.org': 0.40; 'called': 0.40; 'more': 0.63; 'jul': 0.72; 'topic,': 0.79
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=HhaQfRm3mHwjg+r0rNsxsmwOrrA+WrVRVUi7LYb1zoA=; b=M9G8tx4+kjf7dcVWPkMtmamUCqkA4FcAHpYPIyRzryLUqqLFSl8tc+yhIR0TLK2jMl Lq74nn6TSxrCJqSoT7ockoFeNWXBnHVR6VQZAGqSnXHdUFVMW3m3Y9vdzpQzbfuPGGJa DhteuTqop9xbqrvXEIHYkAdgKaSGxjPwuELdOZJqcirQykmgbyLFXsPBkP/EiNwK0j7y 9AbdyXngtRvGG9XN9XwxPfYeMUOU0ifOwGaKpYVAbroFFsjsDpYomS6uAd9RMFAoP4A6 7h+am/ieI1+Crju/lR9HqFHVz+OlgLYILrFzxMX+jDtfK+trygztkd2m3tfoAtKLUGSH BR+A==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=HhaQfRm3mHwjg+r0rNsxsmwOrrA+WrVRVUi7LYb1zoA=; b=l7TwkvvmptlhLwxD4SvMzFtEf/5hvXkwkN0kJrIjiJ174bUXTG1+IpAeYjoPKQGTOG WWf49aLNVo3d3337gSKS/JyUJ0nUvuqUVX8cOr+3h4XTrVoGKPC/l7U8ZfXJio3LywSP 2McgGEVTLvHnZf4XVQjAjXPYEFffKv4eihG2l+NZD4t27A2nm76wHY7YvgHwRSVcBmAq FwiPrI4iyf5S0TQGKkVuV64ib3GyWngUWk4bgEnKXrhg/+mfd3bDYYdq9zsSJOHHM4ZX OVBUYSaRo3EYIfLoG1PiXbEmpH3HfT/spf6fJQocaINYGLJPgeeMj5DMHEAmvAIKKXfh i7Aw==
X-Gm-Message-State ALyK8tIOOiFIxLZFetyoIz6V+tTYlBgrS4Q+xS0NXtfHrXEHHiHUkWAgvdZ8tIB638gPVciMpCPsQk5XjnCTaA==
X-Received by 10.107.30.141 with SMTP id e135mr5173630ioe.103.1467590389528; Sun, 03 Jul 2016 16:59:49 -0700 (PDT)
In-Reply-To <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com>
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 <CACL+1au7XBG7r_JgfL-bDwxfW8j9aoSDfUjFpJME9=s9Y4dHVA@mail.gmail.com>
X-Mailman-Original-References <b9c69ca0-a338-41ec-bfa5-b14510e2cb8f@googlegroups.com> <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> <CALwzidk9AJa0m0086_xKcYearCv34NK8xQ2Q=1SMZv7WbM2yRA@mail.gmail.com> <mailman.30.1467500855.2295.python-list@python.org> <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com>
Xref csiph.com comp.lang.python:111023

Show key headers only | View raw


On Sun, Jul 3, 2016 at 3:32 PM, Steven D'Aprano <steve@pearwood.info> wrote:
>
> But if you prepare the method ahead of time, it works:
>
> from types import MethodType
> instance.method = MethodType(method, instance)

That's a fine way to bind a method, but in the context of this
"descriptor land" topic, I think it's more insightful to call the
function's __get__ method:

    >>> type(method)
    <class 'function'>
    >>> instance.method = method.__get__(instance)
    >>> type(instance.method)
    <class 'method'>
    >>> instance.method.__self__ is instance
    True
    >>> instance.method.__func__ is method
    True
    >>> instance.method()
    method called from self <__main__.Test object at 0x7faf51d1a198>

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


Thread

Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-06-30 18:06 -0700
  Re: Lost in descriptor land Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-30 19:36 -0600
    Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-02 04:27 -0700
  Re: Lost in descriptor land Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-30 20:33 -0700
    Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-02 04:30 -0700
      Re: Lost in descriptor land Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-02 18:02 -0700
        Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-03 06:29 -0700
  Re: Lost in descriptor land Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-30 20:43 -0700
    Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-02 04:32 -0700
      Re: Lost in descriptor land Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-02 17:06 -0600
        Re: Lost in descriptor land Ankush Thakur <ankush.thakur53@gmail.com> - 2016-07-03 06:27 -0700
        Re: Lost in descriptor land Steven D'Aprano <steve@pearwood.info> - 2016-07-04 01:32 +1000
          Re: Lost in descriptor land eryk sun <eryksun@gmail.com> - 2016-07-03 23:59 +0000
            Re: Lost in descriptor land Steven D'Aprano <steve@pearwood.info> - 2016-07-04 11:56 +1000

csiph-web