Affects Perl too
Affects Perl too
Posted Mar 17, 2014 12:13 UTC (Mon) by intgr (subscriber, #39733)In reply to: Affects Perl too by mathstuf
Parent article: A false midnight
Actually I can't think of any from the top of my head. I just said "most" because I suspect there are a few edge cases in the standard library; Python's typing isn't always as strict as people make it out to be. Implicit casts to str are quite common, for example.
> bool('False') -> True (ast.parse_literal is needed) whereas int('1') -> 1
Why do you think this should return False? It doesn't work this way for most other built-in types either, consider list('[1,2]'). The fact that it works for numeric types is a coincidence, because that's a useful way to represent numbers. It never was a goal for sometype(str(value_of_sometype)) return the original value again.
I think using bool(x) to get the truth value of x makes lots of sense, just like list(iterable) does.
> there is no way to pass non-None arguments to str.split and get the no-arg behavior
Agreed, that is inconsistent.
Posted Mar 17, 2014 13:13 UTC (Mon)
by mathstuf (subscriber, #69389)
[Link]
Casts for compound types makes sense since the internal type to parse out is very ambiguous. I would have thought bool would follow int since they're both POD-ish. It bit me in a config parser (it was our pre-existing format, so the stdlib module wasn't going to work) where I passed a function to use to cast the value out from the parse. You could use int, but anything else needed a wrapper function.
Affects Perl too