On Sat, 8 May 2010 02:07:55 am Rob Cliffe wrote:
> Sorry to grouse, but isn't this maybe being a bit too clever?
> Using your example,
>     p1 = partial(operator.add)
> is creating a callable, p1, i.e. a sort of function.  Yes I know
> technically it's not a function, but it behaves very much like one.
>
> Now, if I write
>
>     def f1(x,y): return x+y
>     def f2(x,y): return x+y
>
> I don't expect  f1==f2 to be True, even though f1 and f2 behave in
> exactly the same way,
> and indeed it is not.

I do expect f1==f2, and I'm (mildly) disappointed that they're not.


[...]
> Similarly, if you wanted p1==p2, why not write
>
>     p1 = partial(operator.add)
>     p2 = p1

I thought the OP gave a use-case. He's generating "jobs" (partial 
applied to a callable and arguments), and wanted to avoid duplicated 
jobs.

I think it is reasonable to expect that partial(operator.add, 2) 
compares equal to partial(operator.add, 2). I don't think he's 
suggesting it should compare equal to partial(lambda x,y: x+y, 2).

+0.5 on comparing equal.
+1 on a nicer repr for partial objects.



-- 
Steven D'Aprano
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to