question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dict formatting with 0.16.1

See original GitHub issue

Dict formatting seems weird under 0.16.1. The value is added to a new line under the key, this seems somewhat silly, especially when the line length doesn’t exceed column_limit. I don’t see a tunable to disable this.

[style]
based_on_style = pep8
column_limit = 79
     x = {
-        'ansible_host': '127.0.0.1',
-        'ansible_port': 2222,
-        'ansible_user': 'vagrant',
-        'ansible_private_key_file': '"/foo/bar"',
-        'connection': 'ssh',
+        'ansible_host':
+        '127.0.0.1',
+        'ansible_port':
+        2222,
+        'ansible_user':
+        'vagrant',
+        'ansible_private_key_file':
+        '"/foo/bar"',
+        'connection':
+        'ssh',
         'ansible_ssh_extra_args': ('-o UserKnownHostsFile=/dev/null '
                                    '-o ControlMaster=auto '
                                    '-o ControlPersist=60s '

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:29
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
gongzhitaaocommented, Jul 26, 2018

@r00tat I use

based_on_style = facebook
INDENT_DICTIONARY_VALUE=True
ALLOW_SPLIT_BEFORE_DICT_VALUE=False

And it seems to give you the desired formatting.

0reactions
gabryscommented, Jan 10, 2018

@r00tat I did the same as you and it looks the style is not applied. This is definitely a separate issue, so I suggest raising another issue. I would suggest using a minimal configuration triggering an error:

.style.yapf:

[style]
indent_dictionary_value=true

test.py:

a = {
    "a": "aaaaaaaaaaaaa",
    "b": "bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb  bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb",
}
$ yapf test.py
settings = {
    "a":
        "aaaaaaaaaaaaa",
    "b":
        "bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb  bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb",
}

Now moving .style.yapf to setup.cfg:

$ mv .style.yapf setup.cfg
$ yapf test.py
settings = {
    "a":
    "aaaaaaaaaaaaa",
    "b":
    "bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb  bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb bbbbbbbbbbbbb",
}

Lines “aaaaaaaaaaaaa”, and “bbbbbbbbbbbbb…” are not indented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

https://docs.python.org/2/library/stdtypes.html
No information is available for this page.
Read more >
pandas.to_datetime — pandas 0.25.3 documentation
If True and no format is given, attempt to infer the format of the datetime strings, and if it can be inferred, switch...
Read more >
Python API - xlwings Documentation
Clears the content of the whole sheet but leaves the formatting. clear_formats()#. Clears the format of the whole sheet but leaves the content....
Read more >
Sparse matrices (scipy.sparse) — SciPy v1.9.3 Manual
A sparse array in COOrdinate format. ... Return the lower triangular portion of a matrix in sparse format ... dok_matrix: Dictionary of Keys...
Read more >
yapf · PyPI
Therefore, if you format Python 3 code with YAPF, run YAPF itself under Python ... It's also possible to do the same on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found