Closed dhermes closed 6 years ago
This is now fixed and will be part of 18.3a2. Thanks for all your reports!
Awesome response time, you rock!
@ambv It seems the fix didn't cover all cases. Given moar_numpy.py
:
def delta(points):
return points[:, 1:] - points[:, :-1]
running (from HEAD
)
$ venv/bin/black moar_numpy.py
reformatted moar_numpy.py
the 2nd slice gets "mushed":
diff --git a/moar_numpy.py b/moar_numpy.py
index d9ba020..e36b529 100644
--- a/moar_numpy.py
+++ b/moar_numpy.py
@@ -1,2 +1,2 @@
def delta(points):
- return points[:, 1:] - points[:, :-1]
+ return points[:, 1:] - points[:,:-1]
Alright, will add a test with this example, too. Missed today's release but there should be another one in a few days tops :-)
This should solve your problem once and for all: https://github.com/ambv/black/commit/21c49d942264a1f36858036a9235e5ecb337bf4c
Thanks for another quick fix! I just tried installed the latest
$ git log -1 --pretty=%H
21c49d942264a1f36858036a9235e5ecb337bf4c
$ venv/bin/pip install .
and re-ran it on my mostly converted codebase and it seems there is a regression in how slices are handled. Consider moar_numpy.py
def first_row1d(points):
return points[0, :]
Running
$ venv/bin/black moar_numpy.py
reformatted moar_numpy.py
yields
diff --git a/moar_numpy.py b/moar_numpy.py
index 4a057d6..f1efb82 100644
--- a/moar_numpy.py
+++ b/moar_numpy.py
@@ -1,2 +1,2 @@
def first_row1d(points):
- return points[0, :]
+ return points[0,:]
I promise I'm not trying to be difficult :grinning:. I say regression because black
used to leave those statements alone (I think?).
Sigh...
😂
Is this the last form? If you have any other uses of tuple indexing in your code, list them all please so I can add tests in one go.
Sure thing. I did a git grep [
to find every use of slicing in the project I've been running black
on and found the following comprehensive-ish list of all "slice types":
mat[0, 4]
mat[0, :]
mat[:, i]
mat[0, :2]
mat[:N, 0]
mat[:, 1:3]
mat[:2, :4]
mat[2:4, 1:5]
mat[4:, 2:]
mat[:, (0, 1, 2, 5)]
mat[0, [0]]
mat[:, [i]]
mat.flat[d::d + 1]
mat[:c, c - 1]
mat[1:c + 1, c]
mat[-(c + 1):, d]
mat[:, l[-2]]
mat[:, ::-1]
vec[np.newaxis, :]
I "normalized" the list. I'm sure there are lots more ways that people use slices in the wild. I also have other projects with 3D arrays, so slices like mat[:, :, j]
are common.
Thanks again!
For the repro file
its_science.py
Running
black
(installed fromHEAD
as in #30)changes the "exotic" slice argument:
PS @ambv This is my fourth and last issue (for now) and it's just "wrong" things I encountered when running this on a large codebase of mine. I am SOOOOO happy you have created
black
and look forward to evangelizing it in the community.