Re: Checking Signature of Function Parameter

2011-08-29 Thread Ethan Furman
Travis Parks wrote: I wrote a post a few days ago about how I know the syntax and libraries fairly well, but I don't have the "philosophy". I haven't seen a lot of tricks and I am never sure what is the "norm" in Python. I am sure if an experienced Python programmer looked at my code, they'd imme

Re: Checking Signature of Function Parameter

2011-08-29 Thread Travis Parks
On Aug 29, 1:42 pm, Ian Kelly wrote: > On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks wrote: > > I wanted to allow for calls like this: > > > extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == > > 0).first(lambda x: x % 7 == 0) > > > It allows me to compose method calls similarl

Re: Checking Signature of Function Parameter

2011-08-29 Thread Ian Kelly
On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks wrote: > I wanted to allow for calls like this: > > extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == > 0).first(lambda x: x % 7 == 0) > > It allows me to compose method calls similarly to LINQ in C#. I think > this looks better tha

Re: Checking Signature of Function Parameter

2011-08-29 Thread Travis Parks
On Aug 29, 2:30 am, Nobody wrote: > On Sun, 28 Aug 2011 14:20:11 -0700, Travis Parks wrote: > > More importantly, I want to make sure that > > predicate is callable, accepting a thing, returning a bool. > > The "callable" part is do-able, the rest isn't. > > The predicate may accept an arbitrary s

Re: Checking Signature of Function Parameter

2011-08-29 Thread Dan Stromberg
On Sun, Aug 28, 2011 at 2:20 PM, Travis Parks wrote: > There are some things I want to make sure of. 1) I want to make sure > that source is iterable. 2) More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. > You can check a lot of this stuff ve

Re: Checking Signature of Function Parameter

2011-08-28 Thread Nobody
On Sun, 28 Aug 2011 14:20:11 -0700, Travis Parks wrote: > More importantly, I want to make sure that > predicate is callable, accepting a thing, returning a bool. The "callable" part is do-able, the rest isn't. The predicate may accept an arbitrary set of arguments via the "*args" and/or "**kwar

Re: Checking Signature of Function Parameter

2011-08-28 Thread Chris Rebert
On Sun, Aug 28, 2011 at 2:20 PM, Travis Parks wrote: > I am trying to write an algorithms library in Python. Most of the > functions will accept functions as parameters. For instance, there is > a function called any: > > def any(source, predicate): >    for item in source: >        if predicate(i

Re: Checking Signature of Function Parameter

2011-08-28 Thread Ian Kelly
On Sun, Aug 28, 2011 at 3:20 PM, Travis Parks wrote: > I am trying to write an algorithms library in Python. Most of the > functions will accept functions as parameters. For instance, there is > a function called any: > > def any(source, predicate): >    for item in source: >        if predicate(i

Re: Checking Signature of Function Parameter

2011-08-28 Thread Chris Angelico
On Mon, Aug 29, 2011 at 10:20 AM, Travis Parks wrote: > Maybe I should give up on it, like you said. I am still familiarizing > myself with the paradigm. I want to make sure I am developing code > that is consistent with the industry standards. > In Python, the industry standard is "easier to ask

Re: Checking Signature of Function Parameter

2011-08-28 Thread Travis Parks
On Aug 28, 5:31 pm, Chris Angelico wrote: > On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks wrote: > > > if source is None: raise ValueError("") > > if not isinstanceof(source, collections.iterable): raise TypeError("") > > if not callable(predicate): raise TypeError("") > > Easier: Just ignore the

Re: Checking Signature of Function Parameter

2011-08-28 Thread Chris Angelico
On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks wrote: > > if source is None: raise ValueError("") > if not isinstanceof(source, collections.iterable): raise TypeError("") > if not callable(predicate): raise TypeError("") > Easier: Just ignore the possibilities of failure and carry on with your cod