-
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
Implement flake8-simplify #998
Comments
This plugin is particularly useful because we should be able to autofix most of these. |
I'm working on (These actually require some weird logic whereby we need to be able to peek at the next sibling, so TBD.) |
looking good! I'll keep an eye on this issue and hopefully be able to remove the |
I'm working on |
Ref #998 Co-authored-by: Charlie Marsh <[email protected]>
Flake8 simplify #998 SIM201, SIM202 and SIM208 is done here with fixes. Note: SIM203 == E713 Co-authored-by: Charlie Marsh <[email protected]>
Ref #998 Co-authored-by: Charlie Marsh <[email protected]>
|
Removed, thanks! |
…ening files) (#1782) ref: #998 Co-authored-by: Charlie Marsh <[email protected]>
Ref #998 - Implements SIM401 with fix - Added tests Notes: - only recognize simple ExprKind::Name variables in expr patterns for now - bug-fix from reference implementation: check 3-conditions (dict-key, target-variable, dict-name) to be equal, `flake8_simplify` only test first two (only first in second pattern)
FYI
In the first case, the function returns
|
@jackklika - D'oh, thank you. I'll fix that this afternoon. Must be a flipped condition somewhere. |
Can I implement SIM124? https://github.com/MartinThoma/flake8-simplify#sim909 says:
|
Go for it! |
@charliermarsh Is there a way to compare two expressions while ignoring their contexts? foo = foo
^^^ ^^^
| |
| ---- Name { id: "foo", ctx: Load }
---------- Name { id: "foo", ctx: Store } I tried |
Hmm, no, we don't have anything to support that right now. Although arguably |
Implements SIM113 from #998 Added tests Limitations - No fix yet - Only flag cases where index variable immediately precede `for` loop @charliermarsh please review and let me know any improvements --------- Co-authored-by: Charlie Marsh <[email protected]>
Python-specific rules:
SIM101
("Multiple isinstance-calls which can be merged into a single call by using a tuple as a second argument")SIM105
("Use 'contextlib.suppress(...)' instead of try-except-pass")SIM107
("Don't usereturn
in try/except and finally ")SIM108
("Use the ternary operator if it's reasonable ")SIM109
("Use a tuple to compare a value against multiple values")SIM110
("Use any(...) ")SIM111
("Use all(...)")SIM113
("Use enumerate instead of manually incrementing a counter")SIM114
("Combine conditions via a logical or to prevent duplicating code")SIM115
("Use context handler for opening files")SIM116
("Use a dictionary instead of many if/else equality checks")SIM117
("Merge with-statements that use the same scope")Simplifying Comparisons:
SIM201
("Use 'a != b' instead of 'not a == b'")SIM202
("Use 'a == b' instead of 'not a != b'")SIM203
("Use 'a not in b' instead of 'not (a in b)'")SIM208
("Use 'a' instead of 'not (not a)'")SIM210
("Use 'bool(a)' instead of 'True if a else False'")SIM211
("Use 'not a' instead of 'False if a else True'")SIM212
("Use 'a if a else b' instead of 'b if not a else a'")SIM220
("Use 'False' instead of 'a and not a'")SIM221
("Use 'True' instead of 'a or not a'")SIM222
("Use 'True' instead of '... or True'")SIM223
("Use 'False' instead of '... and False'")SIM300
("Use 'age == 42' instead of '42 == age'")Simplifying usage of dictionaries:
SIM401
("Use 'a_dict.get(key, "default_value")' instead of an if-block")SIM118
("Use 'key in dict' instead of 'key in dict.keys()'")General Code Style:
SIM102
("Use a single if-statement instead of nested if-statements")SIM103
("Return the boolean condition directly")SIM112
("Use CAPITAL environment variables")The text was updated successfully, but these errors were encountered: