Closed
Description
Operating system: macOS 10.13.6
Python version: 3.6.3
Black version: 18.6b4
Does also happen on master: yes
I'm using black --line-length=101 --safe -v
to format a file that contains a snippet like below:
# No f strings or trailing commas after *, *args, or **kwarg parameters elsewhere in the file
class MyClass(BaseClass):
def __init__(
self,
x,
*args,
# Below line is changed by black: trailing comma added
**kwargs
):
try:
super().__init__(
x=x
*args,
# ...But only if the next line also has a trialing comma
**kwargs,
)
except Exception as e:
raise
Black is always adding a trailing comma after the **kwargs
in the def __init__
(below the first comment). This happens even on master and even after clearing black's cache.
A workaround is removing the trailing comma from the **kwargs
in the super().__init__
call (below the second comment), even though this comma is legal in Py3.5:
$ python3.5
>>> class Base:
... def __init__(self, *a, **ka):
... self.a = a
... self.ka = ka
...
>>> class Child(Base):
... def __init__(self, *a, **ka):
... super().__init__(
... *a,
... **ka,
... )
...
>>> c = Child(1, 2, a=3, b=4)
>>> c
<__main__.Child object at 0x10a44e2b0>
>>> c.a
(1, 2)
>>> c.ka
{'b': 4, 'a': 3}