0
if details['box'] == {} or details['box'][last_box_key].get('timeout', datetime.min) < datetime.now():

I tried putting brackets around the dict but I cant seem to break this really long line.

  • Does this answer your question? [Styling multi-line conditions in 'if' statements?](https://stackoverflow.com/questions/181530/styling-multi-line-conditions-in-if-statements) – tevemadar Apr 19 '20 at 09:44

2 Answers2

0

You can break the line up using backslashes.

if details['box'] == {} or \
    details['box'][last_box_key].get('timeout', datetime.min) \
        < datetime.now():
Lemon.py
  • 819
  • 10
  • 22
0

Use black Python code formatter (note: by default, it formats in-place, i.e. mutates the file, use --diff flag to make it just output the changes). Running black test.py formats your code to:

if (
    details["box"] == {}
    or details["box"][last_box_key].get("timeout", datetime.min) < datetime.now()
):

By adding more keys, you may find out how black will split even longer line:

if (
    details["box"] == {}
    or details["box"][last_box_key][another_very_long_key][
        even_more_looooooong_key
    ].get("timeout", datetime.min)
    < datetime.now()
):
Lipen
  • 75
  • 1
  • 5