-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.Issues with the preview and unstable style. Add the name of the responsible feature in the title.F: stringsRelated to our handling of stringsRelated to our handling of stringsT: bugSomething isn't workingSomething isn't working
Description
Describe the bug
Long strings and f-strings are not being formatted to line-width.
New strings created by black are not respecting line-width.
To Reproduce
For example, take this code for variable a:
a = f"{nested_ui_dict_val[i][j][k]['name']} ansible_host={nested_ui_dict_val[i][j][k]['mgmt_ip']} MYPORT=111222333 PATH={nested_ui_dict_val[i][j][k]['path']} ip={nested_ui_dict_val[i][j][k]['ip']} NODESTUFF={nested_ui_dict_val[i][j][k]['nodestuff']} MOREID={nested_ui_dict_val[i][j][k].get('id')} MAINTENANCE={nested_ui_dict_val[i][j][k]['instance_in_maintenance'] or nested_ui_dict_val[i][j][k]['node_in_maintenance']}\n"
b = "a loooooooooooooooooooo oooooooong string with {} and nnnnnnooo sssssssssssssssss ppppppppac overrrrrrrr a limittttttt".format(1)
c = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."And run it against black with --preview:
$ $ python -m black --preview -c 'a = f"{nested_ui_dict_val[i][j][k]['name']} ansible_host={nested_ui_dict_val[i][j][k]['mgmt_ip']} MYPORT=111222333 PATH={nested_ui_dict_val[i][j][k]['path']} ip={nested_ui_dict_val[i][j][k]['ip']} NODESTUFF={nested_ui_dict_val[i][j][k]['nodestuff']} MOREID={nested_ui_dict_val[i][j][k].get('id')} MAINTENANCE={nested_ui_dict_val[i][j][k]['instance_in_maintenance'] or nested_ui_dict_val[i][j][k]['node_in_maintenance']}\n"'The resulting output is:
a = (
f"{nested_ui_dict_val[i][j][k][name]} ansible_host={nested_ui_dict_val[i][j][k][mgmt_ip]} MYPORT=111222333"
f" PATH={nested_ui_dict_val[i][j][k][path]} ip={nested_ui_dict_val[i][j][k][ip]} NODESTUFF={nested_ui_dict_val[i][j][k][nodestuff]} MOREID={nested_ui_dict_val[i][j][k].get(id)} MAINTENANCE={nested_ui_dict_val[i][j][k][instance_in_maintenance] or nested_ui_dict_val[i][j][k][node_in_maintenance]}\n"
)Expected behavior
I expect the subsequent parts of the formatted string to also respect line-width or best fit
a = (
f"{nested_ui_dict_val[i][j][k][name]} ansible_host={nested_ui_dict_val[i][j][k][mgmt_ip]} MYPORT=111222333"
f" PATH={nested_ui_dict_val[i][j][k][path]} ip={nested_ui_dict_val[i][j][k][ip]}"
f" NODESTUFF={nested_ui_dict_val[i][j][k][nodestuff]} MOREID={nested_ui_dict_val[i][j][k].get(id)}"
f" MAINTENANCE={nested_ui_dict_val[i][j][k][instance_in_maintenance] or nested_ui_dict_val[i][j][k][node_in_maintenance]}\n" << not sure about this line.
)Environment
Macos Ventura 13.3.1
python -m black, 23.3.0 (compiled: yes)
Python (CPython) 3.11.3
Additional context
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.Issues with the preview and unstable style. Add the name of the responsible feature in the title.F: stringsRelated to our handling of stringsRelated to our handling of stringsT: bugSomething isn't workingSomething isn't working