sympy/sympy — pull request #827 by toolforger (2011-12-06 23:30:20+00:00)
Title: New: func_equal tests for equality under a test function

This is my idea of a type_tested function, but with the added twist that it can use any lambda that normalizes a single input.

Usage e.g. to normalize variables a and b via the int() function:
a, b = type_tested("int", int, a=a, b=b)
Yes this looks silly, but the keywords are used to generate error messages (they are really strings in disguise if you will).

This is experimental, feedback appreciated.

One thing I don't like already is that the text for the function is explicit as a string, the texts for the values are via keyword parameters. It should really either be type_tested(int=int, a=a, b=b) or type_tested("int", int, "a", a, "b", b).
Except the first variant does not work with lambdas (you can't have special characters and blanks in keywords), and the second makes it harder to use list comprehension (which is supposed to make it fast - this function could be called quite often if we do type testing on internal interfaces).

The other thing is that I should really benchmark whether a list comprehension is really faster than an ordinary Python loop. The current implementation is a bit ugly - that's normal for optimized code, but it better be worth it :-)