-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed _isbool for python 3 #62
base: master
Are you sure you want to change the base?
Conversation
tabulate.py
Outdated
@@ -610,13 +610,21 @@ def _isbool(string): | |||
""" | |||
>>> _isbool(True) | |||
True | |||
>>> _isbool("False") | |||
>>> _isbool(b"false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be b"False" rather than b"false"?
I'd rather see a different test case for b"False" and "False", than the old test being replaced with a new test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should accept both b'false'
and b'False'
, to handle data that doesn't originate from python. For example, in mycli we sometimes get booleans as strings from the SQL connector and would like to display them without parsing. But maybe that's asking too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand where it's coming from, but it's a slippery slope. In no time we'll have to maintain all possible ways to format false and true values (.TRUE.
, FaLsE
, nil
, ...). Probably as a compromise we may decide to accept only "true" and "false", but let them be case-insensitive.
The argument for supporting only "True" and "False": these are Python literals, this is how the library already works.
The argument to supporting "True", "true", "False", and "false": it makes it easier to consume output generated by other programming languages. The argument against: it's a breaking change. The behavior of _isbool("false") -> False
was not documented, but this PR will change it.
The argument to do a case-insensitive match: the same as above.
I'm very reluctant to do breaking changes to this library. Its heuristics are sort of odd, and at this point I'm pretty sure there's someone who relies on "false" being literal text. But I think your suggestion is more practical.
_isbool works incorrectly with binary data in Python 3: