Skip to content

Commit

Permalink
changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Mar 11, 2024
1 parent 5b9e863 commit f59d4da
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
14 changes: 11 additions & 3 deletions CODEMODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ raise AssertionError("this is the only case handled by ruff")

Full test data in tests/recorded/asserts.txt

Ruff supports autofixing B011, but that only covers the precise case of exactly replacing `assert False` with `raise AssertionError`. It does
Ruff supports autofixing B011, but that only covers the precise case of exactly replacing `assert False` with `raise AssertionError`.

## `remove_pointless_parens_around_call`
Removes pointless parentheses wrapping a call.
Expand All @@ -60,7 +60,7 @@ foo(list("abc"))


## `replace_unnecessary_nested_calls`
Resolves flake8-comprehension C414. Ruffs implementation currently breaks sorting stabilityin one case.
Resolves flake8-comprehension C414. Ruffs implementation currently breaks sorting stability in one case.

### Examples
Full test data in `tests/recorded/comprehensions/C414.txt`
Expand All @@ -76,10 +76,11 @@ sorted(sorted(iterable, reverse=True))
sorted(sorted(iterable, reverse=True), reverse=False)
sorted(sorted(iterable, reverse=False), reverse=True)

# unsafe to fix
# unsafe to fix, even if both have the same key function (it might have side-effects)
sorted(sorted(iterable), key=int)
sorted(sorted(iterable, key=bool))
sorted(sorted(iterable, key=bool), key=int)
sorted(sorted(iterable, key=bool), key=bool)
```
#### output
```py
Expand All @@ -97,6 +98,7 @@ sorted(iterable, reverse=True)
sorted(sorted(iterable), key=int)
sorted(sorted(iterable, key=bool))
sorted(sorted(iterable, key=bool), key=int)
sorted(sorted(iterable, key=bool), key=bool)
```


Expand Down Expand Up @@ -261,6 +263,8 @@ else:

try:
1 / 0
except Exception:
...
else:
pass

Expand All @@ -283,6 +287,8 @@ for _ in range(10):

try:
1 / 0
except Exception:
...

if foo:
...
Expand Down Expand Up @@ -350,6 +356,7 @@ with make_context_manager(1) as cm1:
with make_context_manager(1) as cm1, make_context_manager(2) as cm2:
with make_context_manager(3) as cm3:
pass

with make_context_manager(1) as cm1:
with make_context_manager(2) as cm2:
with make_context_manager(3) as cm3:
Expand All @@ -362,6 +369,7 @@ with make_context_manager(1) as cm1:
with make_context_manager(1) as cm1, make_context_manager(2) as cm2:
pass
# Preserve this comment

with (
make_context_manager(1) as cm1,
make_context_manager(2) as cm2,
Expand Down
3 changes: 3 additions & 0 deletions deps/check.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ flake8-print
flake8-simplify
mypy
pep8-naming

# libcst 1.2 drops support for 3.8
libcst<1.2; python_version < "3.9"
12 changes: 7 additions & 5 deletions deps/check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ flake8-print==5.0.0
# via -r deps/check.in
flake8-simplify==0.21.0
# via -r deps/check.in
libcst==1.1.0
# via shed (setup.py)
libcst==1.1.0 ; python_version < "3.9"
# via
# -r deps/check.in
# shed (setup.py)
mccabe==0.7.0
# via flake8
mypy==1.8.0
mypy==1.9.0
# via -r deps/check.in
mypy-extensions==1.0.0
# via
# black
# mypy
# typing-inspect
packaging==23.2
packaging==24.0
# via black
pathspec==0.12.1
# via black
Expand All @@ -79,7 +81,7 @@ pyupgrade==3.15.1
# via shed (setup.py)
pyyaml==6.0.1
# via libcst
ruff==0.3.0
ruff==0.3.2
# via shed (setup.py)
snowballstemmer==2.2.0
# via pydocstyle
Expand Down
8 changes: 4 additions & 4 deletions deps/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ flake8==7.0.0
# via flake8-comprehensions
flake8-comprehensions==3.14.0
# via -r deps/test.in
hypothesis[lark]==6.98.17
hypothesis[lark]==6.99.2
# via
# -r deps/test.in
# hypothesmith
Expand All @@ -44,7 +44,7 @@ mypy-extensions==1.0.0
# via
# black
# typing-inspect
packaging==23.2
packaging==24.0
# via
# black
# pytest
Expand All @@ -58,7 +58,7 @@ pycodestyle==2.11.1
# via flake8
pyflakes==3.2.0
# via flake8
pytest==8.0.2
pytest==8.1.1
# via
# -r deps/test.in
# pytest-cov
Expand All @@ -71,7 +71,7 @@ pyupgrade==3.15.1
# via shed (setup.py)
pyyaml==6.0.1
# via libcst
ruff==0.3.0
ruff==0.3.2
# via shed (setup.py)
sortedcontainers==2.4.0
# via hypothesis
Expand Down
6 changes: 4 additions & 2 deletions src/shed/_codemods.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ def leave(matcher):
This works around https://github.com/Instagram/LibCST/issues/888
by checking if the updated node matches the matcher.
It's possible this problem is no longer possible with the current set of codemods
after removing ones that are implemented by ruff.
"""

def inner(fn):
@wraps(fn)
@m.leave(matcher)
def wrapped(self, original_node, updated_node):
if not m.matches(updated_node, matcher):
# given that this doesn't trigger... can we delete it or do we need a new
# test case with one of the remaining codemods?
# remove this pragma if a test is found&written that triggers the issue
return updated_node # pragma: no cover
return fn(self, original_node, updated_node)

Expand Down

0 comments on commit f59d4da

Please sign in to comment.