You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-07-28.22:58:30.385>created_at=<Date2021-03-15.07:31:24.963>labels= ['interpreter-core', 'type-bug', '3.8', '3.9', '3.10', '3.7']
title='SyntaxWarning for "assertion is always true, perhaps remove parentheses?" does not work with constants'updated_at=<Date2021-07-28.22:58:30.385>user='https://github.com/tsukasa-au'
I would argue that there is none (especially if it is tuple/something that is always true) -- thus why I would assume that Python would provide a warning.
This bug comes from a discussion I was having with someone earlier today where they mentioned that it would be nice if the linter complained about the following::
assert 'not reachable'
That code is incorrect (the assertion will never fire, due to the string evaluating to True). We remembered that python did complain about tuples, and tried to see what the warning looked like using a trivial example::
assert(False, 'msg')
We noticed that this code did not produce a warning on python3.8, but did produce a warning on python2.7.
After much digging we found that the following did work on python3.8::
assert(False, str())
This allowed us to deduce that something special was happening with constants (well, it also required us to look at the disassembly of the ops codes for the above two statements).
Going back to your original question, I have used assert False in code to "test" if a piece of code was being reached. I have also used it for things similar to the piece of code that started all of this::
ifsome_expression:
# ...elifsome_other_expression:
#...else:
assertFalse, 'This code is unreachable'
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: