Auto-formatting code with black - object now if you have a strong opinion

Boris FELD boris.feld at octobus.net
Wed Feb 20 04:26:33 EST 2019


On 19/02/2019 16:28, Augie Fackler wrote:
> On Wed, Feb 13, 2019 at 10:33:15AM +0100, Boris FELD wrote:
>> On 01/12/2018 02:35, Matt Harbison wrote:
>>> On Fri, 30 Nov 2018 07:25:04 -0500, Boris FELD
>>> <boris.feld at octobus.net> wrote:
>>>
>>>> I think using automatic formatting is a great idea and we should move
>>>> forward with this plan. Black seems a good option. I share other's
>>>> concerns about the formatting of import. I also wonder if this also
>>>> applies to list and dict formatting that we tend to express with one
>>>> value per line for clarity.
>>> It looks like yes, unfortunately, if it fits on one line:
>>>
>>> diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py
>>> --- a/hgext/lfs/blobstore.py
>>> +++ b/hgext/lfs/blobstore.py
>>> @@ -289,50 +289,47 @@ class _gitlfsremote(object):
>>>          Return decoded JSON object like {'objects': [{'oid': '',
>>> 'size': 1}]}
>>>          See
>>> https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
>>>          """
>>> -        objects = [{'oid': p.oid(), 'size': p.size()} for p in pointers]
>>> -        requestdata = json.dumps({
>>> -            'objects': objects,
>>> -            'operation': action,
>>> -        })
>>> -        url = '%s/objects/batch' % self.baseurl
>>> +        objects = [{"oid": p.oid(), "size": p.size()} for p in pointers]
>>> +        requestdata = json.dumps({"objects": objects, "operation":
>>> action})
>>> +        url = "%s/objects/batch" % self.baseurl
>>>          batchreq = util.urlreq.request(url, data=requestdata)
>>> ...
>> We have been discussing with the Black author about how we could handle
>> those cases and we found a `hack` which is adding an empty comment on
>> the first line of a list, dict, multi-line construction:
> If you're talking to Łukasz, could you float the way clang-format
> works by him? That is, if a trailing comma is present in the literal
> it's formatted one element per line, but if there's no trailing comma
> it's formatted compactly. I've found that to be a good tradeoff. It'd
> also make our import blocks format correctly without modification.
He is quite aware of that option and seems to have decided against it
for good. He pointed us toward the # hack instead saying it works but
finding it inelegant. (So we seems to be in a case of "Ĺukasz doesn't
want people to use this hack, but he seems to be even less willing to
offer a cleaner alternative")


More information about the Mercurial-devel mailing list