Describe the bug
https://github.com/fossasia/open-event-server/blob/development/app/api/helpers/utilities.py#L28-L34 is exceedingly convoluted, does __type(x)__ compares contrary to PEP8, and contains several logic errors. A code review of this function would be a worthwhile effort. Some __doctests__ would really be helpful here.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Stacktrace
Additional details (please complete the following information):
3.5, 3.6]HEAD Commit hash [e.g. 4629c62]Additional context
Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.71. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!
Links: app homepage, dashboard and code for this bot.
Yup. it was created when Python 2 to 3 migration/compatibility was needed
There are no doctests, but I think it has some unit tests. If not, they'll be added
There are unit tests. The behaviour is flaky though. None should return True, it is returning False
Perhaps add a few more tests for clarity:
self.assertTrue(string_empty(' ')) # <space><space>
self.assertTrue(string_empty(' ' * 20)) # <space> * 20
self.assertFalse(string_empty(0)) # an int
self.assertFalse(string_empty(0.0)) # a float
self.assertFalse(string_empty([])) # a list
self.assertFalse(string_empty(False)) # a bool
self.assertTrue(string_empty('\t \n')) # <tab><space><return>
Does this codebase still support Python 2 or not?
From README.md it looks like legacy Python can be dropped so:
def string_empty(value: str) -> bool:
if isinstance(value, str):
return not value.strip()
return False
def string_empty(value: str) -> bool:
return isinstance(value, str) and not value.strip()