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


Groups > comp.lang.python > #105222 > unrolled thread

Re: monkey patching __code__

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2016-03-18 08:48 -0600
Last post2016-03-18 08:48 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#105222 — Re: monkey patching __code__

FromIan Kelly <ian.g.kelly@gmail.com>
Date2016-03-18 08:48 -0600
SubjectRe: monkey patching __code__
Message-ID<mailman.325.1458312523.12893.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web