On Sep 9, 11:47 am, 7stud <bbxx789_0...@yahoo.com> wrote: > On Sep 9, 10:45 am, Andrey Fedorov <anfedo...@gmail.com> wrote: > > > > > > > Hi all, > > > I've written a function [1] called apply_some which takes a set of > > keywords arguments, filters only those a function is expecting, and > > calls the function with only those arguments. This is meant to > > suppress TypeErrors - a way to abstract the logic which checks what > > arguments a passed-in function accepts. > > > For example: > > > > def foo(x=1, y=2): > > > return (x,y) > > > > apply_some(foo, y=0, z="hi") // calls foo(y=0) > > > -> (1,0) > > > I'd like to expand this to fill undefined arguments with None, but > > before I do, does anyone know of any packages/libraries which either > > do something similar or would make this code cleaner? > > > Cheers, > > Andrey > > > 1.http://gist.github.com/183375 > > It sounds like all you are doing is moving type checking out of the > original function and into another function.
I'm not sure where you got the idea that he was doing type checking, unless you just saw the word "TypeError" and made a knee-jerk assumption about what was he was doing. If you'd have bothered trying to understand the post you would have seen that he was filtering arguments by name. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list