Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: eryk sun Newsgroups: comp.lang.python Subject: Re: Lost in descriptor land Date: Sun, 3 Jul 2016 23:59:09 +0000 Lines: 22 Message-ID: References: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de M6Qr9yiwuSKV1790O84hfwHd2RLKSGPS57NLgUo4JGaw== Return-Path: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:111023 On Sun, Jul 3, 2016 at 3:32 PM, Steven D'Aprano 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) >>> instance.method = method.__get__(instance) >>> type(instance.method) >>> instance.method.__self__ is instance True >>> instance.method.__func__ is method True >>> instance.method() method called from self <__main__.Test object at 0x7faf51d1a198>