George Sakkis a écrit : > John Machin wrote: > >>Bruno Desthuilliers wrote: >> >> >>><my humble opinion> >>>Python is dynamic, and fighting against the language is IMHO a really >>>bad idea. The only places where theres a real need for this kind of >>>stuff are when dealing with the "outside world" (IOW : inputs and >>>outputs). And then packages like formencode can do much more than mere >>>type-checking >>></my humble opinion> >> >>Agreed. The worst case I have seen: >> >>An elaborate decorator (similar to the OP's) laboriously checks arg >>types. That's IMHO not "consenting adults" territory. But it gets a >>whole lot worse when it's applied to a method whose body is like this: >> >>if isinstance(.... >> action_for_type1(... >># big snip >>elif isinstance(... >> action_typeN( ... >># no else statement > > > Ouch.. someone must have skipped his/her OO class... > Depends... I've sometimes had to write such kind of horrors - at least once: a wrapper class to ensure that all strings accessible directly *or indirectly* (via a dict, list, method call, whatever...) would be unicode strings...
But of course I didn't use decorators to type-check annything !-) -- http://mail.python.org/mailman/listinfo/python-list