[issue23653] Make inspect._empty test to False
Yury Selivanov added the comment: Nathan, consider the following signature: def foo(a=0:''): pass now, sig.parameters['a'].annotation will be '' and .default will be 0, and they will fail 'if param.annotation or param.default' check. That's why we encourage checks like 'if param.annotation is not param.empty'. Closing this issue. -- assignee: - yselivanov nosy: +yselivanov resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23653 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23653] Make inspect._empty test to False
Nathan West added the comment: Doesn't the same issue exist for all other uses of the idiom, though? Python provides container truthiness even though `len(x) == 0` is more correct. On Fri, Jun 5, 2015, 3:20 PM Yury Selivanov rep...@bugs.python.org wrote: Yury Selivanov added the comment: Nathan, consider the following signature: def foo(a=0:''): pass now, sig.parameters['a'].annotation will be '' and .default will be 0, and they will fail 'if param.annotation or param.default' check. That's why we encourage checks like 'if param.annotation is not param.empty'. Closing this issue. -- assignee: - yselivanov nosy: +yselivanov resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23653 ___ -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23653 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23653] Make inspect._empty test to False
New submission from Nathan West: A common Python idiom is to test objects by value in an if. This includes container emptiness and regular expression matches, or using 'or' to specify a default value: if my_list: # list isn't empty if regex.match(string): # string matched the regex my_list = arg or [1,2,3] It'd be nice if we could use this idiom with inspect.Signature._empty or inspect.Parameter.empty: sig = signature(func) for param in sig.parameters.values(): if param.annotation: ... or, to use a the example that motivated this idea: def arg_type(param): return param.annotation or str The only issue I can think of is that, if an annotation or default value is some False value, like None, than the test will fail even if the value isn't _empty. However, this issue already exists for other uses of this idiom, and I think this is a perfect extension of the form. -- components: Library (Lib) messages: 237987 nosy: Lucretiel priority: normal severity: normal status: open title: Make inspect._empty test to False type: enhancement versions: Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23653 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com