Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

How would you expect this to be formatted? #105

Open
jondot opened this issue May 25, 2018 · 3 comments
Open

How would you expect this to be formatted? #105

jondot opened this issue May 25, 2018 · 3 comments

Comments

@jondot
Copy link

jondot commented May 25, 2018

this is hand-tuned, yapf/pep8 don't really care about any of that (they pass-through, it seems):

def fetch(content, prefix):
    return {
        'parts': pipe(parse('$..layers').find(content), mapcat(lambda m: m.value),
                      filter(lambda v: v['exportOptions']['exportFormats']),
                      filter(lambda v: re.match(prefix, v['name'])),
                      map(lambda v: glom(v, {'key': 'name',
                                             'layout': ('frame', {'left': ('x', round),
                                                                  'top': ('y', round),
                                                                  'width': ('width', round),
                                                                  'height': ('height', round)}) })),
                      sorted(key=lambda p: p['key']),
                      list)
    }

with prettier

def fetch(content, prefix):
    return \
        {
            "parts":
                pipe(parse("$..layers").find(content), mapcat(lambda m: \
                        m.value), filter(lambda v: \
                        v["exportOptions"]["exportFormats"]), filter(lambda \
                        v \
                    : \
                        re.match(prefix, v["name"])), map(lambda v: \
                        glom(v, {
                            "key": "name",
                            "layout":
                                (
                                    "frame",
                                    {
                                        "left": ("x", round),
                                        "top": ("y", round),
                                        "width": ("width", round),
                                        "height": ("height", round)
                                    }
                                )
                        })), sorted(key=lambda p: p["key"]), list)
        }
@hawkrives
Copy link

I'd probably do this by hand, but my formatting can be a bit idiosyncratic.

def fetch(content, prefix):
    return {
        'parts': 
            pipe(
                parse('$..layers').find(content), 
                mapcat(lambda m: m.value),
                filter(lambda v: v['exportOptions']['exportFormats']),
                filter(lambda v: re.match(prefix, v['name'])),
                map(lambda v: glom(v, {
                    'key': 'name',
                    'layout': (
                        'frame', 
                        {
                            'left': ('x', round),
                            'top': ('y', round),
                            'width': ('width', round),
                            'height': ('height', round)
                        }
                    ) 
                })),
                sorted(key=lambda p: p['key']),
                list
            )
    }

(I can try and write out the general rules I followed here, if this isn't too hard on the eyes.)

@jondot
Copy link
Author

jondot commented May 25, 2018

Looks much better! is this anything yapf/pep8/prettier could ever do?

@jondot
Copy link
Author

jondot commented May 26, 2018

FWIW, unrelated to this thread, I saw this project on HN this morning https://github.com/ambv/black seems to be exactly what I was looking for (an opinionated formatter), and also incidentally it formats code almost exactly like you did. hurray! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants