-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[CI] Update dummy-variable regex for pylint #17206
[CI] Update dummy-variable regex for pylint #17206
Conversation
Prior to this commit, the regex used for pylint to identify dummy variables would correctly identify variables that start with an underscore (e.g. `_scale`), unless they have an underscore elsewhere in the name (e.g. `_scale_factor`). This leads to false positives from pylint for unused variables, as prefixing a variable with an underscore should mark a variable as intentionally unused. This commit updates the regex in TVM's `pylintrc` to match the current default value for `dummy-variables-rgx`, to allow unused variables to be named with a leading underscore, even if they also contain another underscore.
I ran into this false positive for #17201 for a variable named |
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.
Since we're already using names starting with _
to represent dummy variables, it makes sense to allow _
in other places as part of the name.
One thing though is that PEP 8 style guide suggests using names starting with _
to be used as "weak" internal use variables, and the convention I've used till now is that unused variables are named with just an _
like x, _ = get_xy()
. So, my question is why do we want to name unused variables in general? Could we not just use _
?
Mainly to indicate to a reader which return values are being ignored. As an example, suppose there's a function that produces a # A reader may not know what the first two return values are.
_, _, attrs = define_function(relax_args)
# The first two return values are a function and parameters to
# that function.
_func, _params, attrs = define_function(relax_args) I've run into a few cases where the same return value was re-generated, because a later developer wasn't aware that it was already being generated. By explicitly naming the unused return value, this becomes less likely. (e.g. Seeing Obviously, this shouldn't be applied in all cases, as |
Makes sense, thanks for your reply. |
Prior to this commit, the regex used for pylint to identify dummy variables would correctly identify variables that start with an underscore (e.g.
_scale
), unless they have an underscore elsewhere in the name (e.g._scale_factor
). This leads to false positives from pylint for unused variables, as prefixing a variable with an underscore should mark a variable as intentionally unused.This commit updates the regex in TVM's
pylintrc
to match the current default value fordummy-variables-rgx
, to allow unused variables to be named with a leading underscore, even if they also contain another underscore.