-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
WIP: Add invalid-envvar checkers #1680
Conversation
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.
The initial effort is pretty good! There are a couple of changes that we need though
@@ -0,0 +1,5 @@ | |||
import os |
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.
Take a look at the other test files from the functional
directory. The .txt
should be a mapping of the error occurrences from the .py
file.
pylint/checkers/stdlib.py
Outdated
@@ -287,6 +317,42 @@ def _check_open_mode(self, node): | |||
self.add_message('bad-open-mode', node=node, | |||
args=mode_arg.value) | |||
|
|||
def _check_invalid_envvar_value(self, call_arg, infer): | |||
if isinstance(call_arg, Call): |
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.
We have an utility called safe_infer which you should use instead.
pylint/checkers/stdlib.py
Outdated
return | ||
|
||
if isinstance(call_arg, Const): | ||
if not isinstance(call_arg.value, (six.string_types, six.text_type)): |
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.
six.string_types
should be enough since it will contain both unicode
and str
on Python 2.
pylint/checkers/stdlib.py
Outdated
|
||
if isinstance(call_arg, Const): | ||
if not isinstance(call_arg.value, (six.string_types, six.text_type)): | ||
self.add_message('invalid-envvar-value', node=call_arg, args=(infer.qname(), call_arg.pytype())) |
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.
This should be the node that you are checking against, not the inferred node (e.g the node from the visit_
function)
Guys, could you please tell how to generate the |
@femdom Hello, and sorry for late response. Parametrized test runner ( |
@femdom Let us know if you need any help generating that file! Other than that, this PR seems close to being merged |
@femdom I updated the tests and merged this locally. Thank you so much for the contribution and sorry for the huge delay getting this in! |
Features
getenv
functionsFor the ticket #1669