-
-
Notifications
You must be signed in to change notification settings - Fork 7
No single letter variables #25
No single letter variables #25
Conversation
@MarcoGorelli This is giving an error with the mypy precommit hook ( |
Codecov Report
@@ Coverage Diff @@
## main #25 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 47 49 +2
Lines 633 659 +26
Branches 80 84 +4
=========================================
+ Hits 633 659 +26
Continue to review full report at Codecov.
|
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.
Awesome work, I'm really impressed you figured this all out!
For the mypy
issue, we just need to "help" mypy and tell it that the target elements are ast.Name
s, and hence that they have the id
attribute. You probably want to write it like this:
for item in assignment_names:
if isinstance(item, ast.Name) and item.id != "_" and len(item.id) == 1:
yield node.lineno, node.col_offset, MSG
cc @jbrockmendel in case you have comments - this'll raise an error all over the place in pandas, but it can be fixed incrementally
This is pretty neat. |
Thanks for taking a look - @klssmith if you mark this as "ready for review" we can merge it |
7fcbe1a
to
a67aecc
Compare
Thanks for the comments. @MarcoGorelli I've made the change needed to pass the mypy precommit check. I've not changed this to ready to review just yet because I've noticed that the abc, d = (5, 6) gives the warning of
Since the single letter variable is at col_offset 6, I assume the message should read |
when you're in the |
This allows `_` to be used as a variable name, since it is conventionally used for throwaway variables, but does not allow any other single letter variables. The `target` method of `ast.Assigns` will normally contain a list of nodes, however for an unpacking assignment (such as `'a,b = c'`) it will contain an `ast.Tuple` or an `ast.List` so we need to cover for all cases.
a67aecc
to
1c6f213
Compare
👍 I was able to replace |
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.
Thanks for the help @MarcoGorelli! I will check out pyupgrade |
This allows
_
to be used as a variable name, since it is conventionallyused for throwaway variables, but does not allow any other single letter
variables.
The
target
method ofast.Assigns
will normally contain a list of nodes,however for an unpacking assignment (such as
'a,b = c'
) it will containan
ast.Tuple
or anast.List
so we need to cover for all cases.