Message237987
| Author |
Lucretiel |
| Recipients |
Lucretiel |
| Date |
2015年03月12日.21:31:49 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1426195909.5.0.733462239813.issue23653@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2015年03月12日 21:31:49 | Lucretiel | set | recipients:
+ Lucretiel |
| 2015年03月12日 21:31:49 | Lucretiel | set | messageid: <1426195909.5.0.733462239813.issue23653@psf.upfronthosting.co.za> |
| 2015年03月12日 21:31:49 | Lucretiel | link | issue23653 messages |
| 2015年03月12日 21:31:49 | Lucretiel | create |
|