The new version of black
is consistent in how it handles the magic trailing commas. So if we upgrade black
and apply it, lots of files will be changed. However, the diff needn't be so large if we remove unnecessary trailing commas before upgrading.
E.g. in pandas/core/aggregation.py there is
def reconstruct_func(
func: Optional[AggFuncType], **kwargs,
) -> Tuple[
bool, Optional[AggFuncType], Optional[List[str]], Optional[List[int]],
]:
which has an unnecessary trailing comma.
The new version of black
would transform this as
def reconstruct_func(
func: Optional[AggFuncType],
**kwargs,
) -> Tuple[bool, Optional[AggFuncType], Optional[List[str]], Optional[List[int]],]:
However, if we instead remove the trailing comma and write it as
def reconstruct_func(
func: Optional[AggFuncType], **kwargs
) -> Tuple[bool, Optional[AggFuncType], Optional[List[str]], Optional[List[int]]]:
then both the current and the new versions of black will be OK with it.
So, PRs to remove some unnecessary trailing commas would be welcome - perhaps keep each PR limited to 5-10 files changed.
Files that (may) need changing are:
updated list of files which need changing
See https://github.com/pandas-dev/pandas/pull/35930, #35949, #35950 and for examples of how to open a PR for this.
No need to ask for permission to work on this, just choose a few files to work on and open a PR (optionally, you can comment here indicating that you're working on them)
I think the easiest way to find them is actually to let black (using the latest version) reformat the file(s), and then check in the diff for which ones the trailing comma can be removed (and then run black again)
I am looking at these right now
edit: https://github.com/pandas-dev/pandas/pull/35956
@MarcoGorelli if it looks good I can open another with some more later today.
@jpribyl thanks! Yes, feel free to do so, any help here would be appreciated!
https://github.com/pandas-dev/pandas/pull/35959
with several more files:
working on these right now:
I'm searching using this regex: ,\n? *\)|,\n? *\]
What do you guys think? Is it the correct way?
Edit: ,\n? *(\)|\]|\})
I'm searching using this regex:
,\n? *\)|,\n? *\]
What do you guys think? Is it the correct way?Edit:
,\n? *(\)|\]|\})
I would just upgrade black
, run it on the chosen files, see what's changed, remove trailing commas, and run black
again
I would just upgrade
black
, run it on the chosen files, see what's changed, remove trailing commas, and runblack
again
@MarcoGorelli when I am running black again, it changes file back with trailing commas
I would just upgrade
black
, run it on the chosen files, see what's changed, remove trailing commas, and runblack
again@MarcoGorelli when I am running black again, it changes file back with trailing commas
That's fine. Two things may happen when running the new version of black
:
It's the second case in which we want to remove the trailing commas, so that both the current and the new version of black
would reformat that line in the same way.
From a quick glance it looks like you've done it correctly anyway, will review later today
Working on these files:
Now Working on
Working on:
Working on these files
hello, I'm new to this community.. Now I'm working on these files :
Working on:
Working On:
pandas/tests/series/methods/test_interpolate.py
pandas/tests/series/methods/test_unstack.py
pandas/tests/series/test_cumulative.py
pandas/tests/test_algos.py
Working On:
pandas/tests/scalar/test_na_scalar.py
pandas/tests/scalar/timestamp/test_arithmetic.py
pandas/tests/scalar/timestamp/test_constructors.py
working on:
working on:
Most helpful comment
https://github.com/pandas-dev/pandas/pull/35959
with several more files: