partial with skipped arguments

I often wish you could bind to arguments in a partial out of order, skipping some positionals. The solution I came up with is a singleton object located as an attribute of the partial function itself and used like this: def foo(a, b): return a / b pf = partial(foo, partial.skip, 2) assert pf(1.0) == 0.5 -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/

On 4/21/07, Calvin Spealman <ironfroggy@gmail.com> wrote:
The other way I've seen this proposed is as:: rpartial(foo, 2) In this particular situation, you could also just write:: partial(foo, b=2) I think the presence of keyword argument support is why rpartial wasn't added originally. Steve -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On 4/22/07, Steven Bethard <steven.bethard@gmail.com> wrote:
Relying on the names of position arguments is not always a good idea, of course. Also, it doesn't work at all with builtin (and extension?) functions. The design is a little different, but I like it. Also, the rpartial idea just creates multiple names for essentially the same thing and still doesn't allow for skipping middle arguments or specify only middle arguments, etc. I'd like to write a patch, if it would be considered. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/

On 4/22/07, Calvin Spealman <ironfroggy@gmail.com> wrote:
Well, I can pretty much guarantee you'll get the two responses above, so if you post a patch, make sure you let python-dev know that you've already considered these options and don't see them as satisfactory. Your best bet of convincing people is probably to find a few real-world use cases and post the corresponding code. Steve -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On 4/22/07, Collin Winter <collinw@gmail.com> wrote:
More or less but that posses two problems that I mentioned previously: 1) Relying on the names of position arguments does not feel right. 2) Buitin and extension functions don't work with that because you can't pass positionals to them by name. Besides, its a good excersize for me to finally get into any moderately real hacking of CPython. I'm working on the patch right now, one way or the other. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/

On 4/21/07, Calvin Spealman <ironfroggy@gmail.com> wrote:
The other way I've seen this proposed is as:: rpartial(foo, 2) In this particular situation, you could also just write:: partial(foo, b=2) I think the presence of keyword argument support is why rpartial wasn't added originally. Steve -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On 4/22/07, Steven Bethard <steven.bethard@gmail.com> wrote:
Relying on the names of position arguments is not always a good idea, of course. Also, it doesn't work at all with builtin (and extension?) functions. The design is a little different, but I like it. Also, the rpartial idea just creates multiple names for essentially the same thing and still doesn't allow for skipping middle arguments or specify only middle arguments, etc. I'd like to write a patch, if it would be considered. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/

On 4/22/07, Calvin Spealman <ironfroggy@gmail.com> wrote:
Well, I can pretty much guarantee you'll get the two responses above, so if you post a patch, make sure you let python-dev know that you've already considered these options and don't see them as satisfactory. Your best bet of convincing people is probably to find a few real-world use cases and post the corresponding code. Steve -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On 4/22/07, Collin Winter <collinw@gmail.com> wrote:
More or less but that posses two problems that I mentioned previously: 1) Relying on the names of position arguments does not feel right. 2) Buitin and extension functions don't work with that because you can't pass positionals to them by name. Besides, its a good excersize for me to finally get into any moderately real hacking of CPython. I'm working on the patch right now, one way or the other. -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/
participants (3)
-
Calvin Spealman
-
Collin Winter
-
Steven Bethard