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


Groups > comp.lang.python > #105222

Re: monkey patching __code__

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: monkey patching __code__
Date Fri, 18 Mar 2016 08:48:01 -0600
Lines 30
Message-ID <mailman.325.1458312523.12893.python-list@python.org> (permalink)
References <56EBEB5A.7050207@mail.de> <CALwzid=XVSnSEt14Oer-2dO-0kT+fLi1EP4mNehXc0+zDqTX=g@mail.gmail.com> <56EC1169.1030304@mail.de>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de /BJ/bopCFrBrf/cCqz1HCQjWp/lZy7ASDhv8jmPSAXEg==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'defaults': 0.05; 'cc:addr :python-list': 0.09; 'suggestions.': 0.09; 'template': 0.11; ':-)': 0.12; 'django': 0.13; '2016': 0.16; 'attribute?': 0.16; 'better:': 0.16; 'cc:name:python': 0.16; 'declaration,': 0.16; 'function?': 0.16; 'globals.': 0.16; 'intrinsic': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'suggestion.': 0.16; 'sure.': 0.16; 'wrote:': 0.16; '&gt;': 0.18; 'featured': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'do.': 0.22; 'trying': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'mostly': 0.27; 'message-id:@mail.gmail.com': 0.27; 'object,': 0.27; 'function': 0.28; 'lot.': 0.29; 'objects': 0.29; "i'm": 0.30; 'code': 0.30; 'another': 0.32; 'especially': 0.32; 'surely': 0.33; 'open': 0.33; 'add': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'thanks': 0.37; 'received:209.85.213': 0.37; 'version': 0.38; 'received:209': 0.38; 'why': 0.39; "didn't": 0.39; 'takes': 0.39; 'some': 0.40; 'your': 0.60; 'different': 0.63; 'our': 0.64; 'it!': 0.64; 'mar': 0.65; 'reverse': 0.66; 'behaviors': 0.72; 'sounds': 0.76; 'hoping': 0.77; 'to:none': 0.91
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:cc; bh=bBeXhb4f/28tO3KIlNmz6KBEOlWkctKspIf2jf01sck=; b=v+2u05+jo0DRl5zAdI0rmB1qPSC0JqDLsTqGrJnxLaXZTvCH6FWyFyu+4TmQjhJZsh JDSGIoM04e6p2Xzv2bxOEI3LFmqWg5gQUp0WFvZd6DEKQYULZHObSexDdIypWUiwVK++ uCtk2chstF/W/GnsBi6pmAuPcuvmedZ2kQp6lvyeC/Vj8vzK7XGtTmsE3sVTMIrUt2D9 55JPoYlie+6OuEGn+H+T7WVXVBZ6uvQkV6giE6WwIAcrxRgWdvrNt0DIb4K4GgBhZ/+a bJKMn17eQfovjkfNHMukiO/rXs7u2s+ke+AUTpUgvwTbkMdHb1bJBqUsxHm6cK82cu92 dlJw==
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:cc; bh=bBeXhb4f/28tO3KIlNmz6KBEOlWkctKspIf2jf01sck=; b=nK4Xp8lelKjubcqy3RX77SmvVP5xcc79BRAnhnfvMHFvP9+hghksplhUstTUZajNye 0eSXQ/UjNoRY9xmMr5PKWXKgUwngHlclNA4DaKV2+gIl3PMrjgC2MYk7kASdVu5S6wYs 12OZzoG3CkN5mKYsJdFhJbw1Ge99GP8gq3Gwgk6fk96/oOW75YiMbd20R9VI7KtTf/qe J7YMyP5SSVgcaM/fjfnaoGkuTbEMZdJwPOqGVfQ+hOsM3kTQYAQ44ohyNHu+bTu+IL+f G+D3B4sOcHKyETumb4yQgTJktD9sv6UYZKVGmfPun7WsRiQZkpiFOoKP7WTAvLn01n+j j39w==
X-Gm-Message-State AD7BkJIfekDICpfA6HGcFmvlG/fD9QRm6FkmHQ3/OK3zQ/n513BLvCNxyqYvB4vwrA5CitI1pUanotaIGgzhyg==
X-Received by 10.50.13.37 with SMTP id e5mr559426igc.85.1458312520928; Fri, 18 Mar 2016 07:48:40 -0700 (PDT)
In-Reply-To <56EC1169.1030304@mail.de>
X-Content-Filtered-By Mailman/MimeDel 2.1.21
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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>
Xref csiph.com comp.lang.python:105222

Show key headers only | View raw


On Mar 18, 2016 8:33 AM, "Sven R. Kunze" <srkunze@mail.de> wrote:
>
> On 18.03.2016 14:47, Ian Kelly wrote:
>>
>> Your patched version takes two extra arguments. Did you add the
>> defaults for those to the function's __defaults__ attribute?
>
>
> That's it! :-) Thanks a lot.
>
> Just to understand this better: why is that not part of the code object
but part of the function?

Well I didn't design it, so I'm not really sure. But it could be argued
that the defaults are intrinsic to the function declaration, not the code
object, as not all code objects even have arguments. It also makes it
straight-forward to create a new function that uses the same code but with
different defaults or globals.

>> This sounds like a pretty hairy thing that you're trying to do. Surely
>> there must be some better way to accomplish the same goal.
>
>
> We are open for suggestions. We featured our own reverse function for a
while but it lead to inconsistent behaviors across the field. Especially
considering that Django provides an {% url %} template tag which would then
use yet another reverse implementation.

I don't really have a good suggestion. I was mostly hoping that Django
provided a way to hook in a different implementation.

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


Thread

Re: monkey patching __code__ Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-18 08:48 -0600

csiph-web