25 Jul
2011
25 Jul
'11
3:38 p.m.
On 07/25/2011 05:44 AM, Herman Sheremetyev wrote:
Giving those first two positional arguments default values (empty string and empty tuple?) would make it even better:
obj = type(foo=lambda self, x: x)()
That's only one set of parens away from my initial proposal, but I think it's close enough. Would there be any objections to changing the type() API to support this?
-1 on changing type(). Just add this to your code:
def mytype(**kwargs): ... return type('', (), kwargs)()
Then you can get rid of the extra parens:
obj=mytype(foo=lambda self, x: x) obj.foo(3) 3
Eric.