Nick Coghlan, 08.02.2013 16:08: > On Sat, Feb 9, 2013 at 12:09 AM, Stefan Behnel wrote: >> I'm wondering about the purpose of this code in >> inspect.Signature.from_function(): >> >> """ >> if not isinstance(func, types.FunctionType): >> raise TypeError('{!r} is not a Python function'.format(func)) >> """ >> >> Is there any reason why this method would have to explicitly check the type >> of its argument? Why can't it just accept any object that quacks like a >> function? > > Primarily because the expected approach for alternative objects that > want to expose signature in 3.3 was for them to provide the > __signature__ attribute directly, rather than providing the far > messier grab bag of eclectic attributes exposed by native Python > functions (there's also a tentative plan kicking around somewhere to > have a string version for 3.4, so we can start doing something useful > with functions implemented in C). > > I suspect the specific reason for the lack of ducktyping is merely to > provide a nice error message when people call the class method rather > than the module level function, so removing the check sounds > reasonable to me. The ultimate decision will be Georg's as RM, > though. Probably the quickest way to get a decision from him would be > a tracker issue set to release blocker, with a patch removing those > two lines and a test confirming that non-functions with the right > attributes are correctly accepted (e.g. by copying the attributes from > a real function to a custom object and checking > Signature.from_function gives the same answer). Thanks for the feedback, patch is up. https://bugs.python.org/issue17159 Stefan
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4