Skip to content
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

warning when asserts have a string literal as condition #3284

Closed
rjthomson opened this issue Dec 3, 2019 · 3 comments · Fixed by #3346
Closed

warning when asserts have a string literal as condition #3284

rjthomson opened this issue Dec 3, 2019 · 3 comments · Fixed by #3346
Labels
Checkers Related to a checker Good first issue Friendly and approachable by new contributors

Comments

@rjthomson
Copy link

A common mistake is to write asserts with a message as the only parameter.
For example:
assert "unreachable code"
instead of:
assert False, "unreachable code"
In the malformed case, the string will evaluate as True and the assertion will never hit.

Could Pylint warn if an assert has a string literal as the first parameter?

@PCManticore
Copy link
Contributor

This is a good suggestion, thank you.

@PCManticore PCManticore added Checkers Related to a checker Good first issue Friendly and approachable by new contributors labels Dec 3, 2019
@anubh-v
Copy link
Contributor

anubh-v commented Jan 14, 2020

@PCManticore, may I work on this?
My current idea is to implement the logic for this check in the following method of BasicChecker
https://github.com/PyCQA/pylint/blob/a4136c14b98e65e1fe0bab4ec28564700ef983ed/pylint/checkers/base.py#L1380-L1388

@PCManticore
Copy link
Contributor

@anubh-v Sure thing, feel free to tackle any issue you don't see assigned already.

PCManticore pushed a commit that referenced this issue Jan 14, 2020
This check is emitted whenever **pylint** finds an assert statement
with a string literal as its first argument. Such assert statements
are probably unintended as they will always pass.

Close #3284
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants