[MRG+1] default return value for extract_first #1145
Conversation
I like it. |
@bosnj Simple test plz |
I like it too. Should we add a default to Documenting it would be good too, a simple use-case (like the one on this issue's description) in |
I'm fine with this feature.
|
Also, it may be a right time to start adding docstrings to new methods/features. |
for x in self: | ||
return x.extract() | ||
return x.extract() or default |
dangra
Apr 29, 2015
Member
It doesn't look good to me. It is returning the default value only if first matched selection is an empty string.
I think the default value should be used only when there aren't matches like in:
for x in self:
return x.extract()
else:
return default
It doesn't look good to me. It is returning the default value only if first matched selection is an empty string.
I think the default value should be used only when there aren't matches like in:
for x in self:
return x.extract()
else:
return default
Thanks @dangra, updated as per your suggestion. |
LGTM. I'd like the same feature in |
[MRG+1] default return value for extract_first
let's sneak this in :) |
|
It would be useful to have a default return value for
extract_first
, to avoid additional data type checks.For example, when expecting a string, this would raise an exception:
something = selector.extract_first().lower()
Allowing an optional
default
value can solve this elegantly:something = selector.extract_first(default='').lower()