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.

Handle multiline import-from statements

See original GitHub issue

consider

11:03 AM noon ∈ meh.py>cat meh.py 
from math import (
        sqrt,
        log
    )

print(log(2))
11:03 AM noon ∈ meh.py>autoflake --remove-all-unused-imports meh.py 

😦

11:03 AM noon ∈ meh.py>autoflake --version
autoflake 0.6.6

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
johncallscommented, Oct 18, 2018

There exists a possible workaround in combination with isort:

  • Reformat every import into one line: isort -rc -sl .
  • Use autoflake to remove unused imports
  • Reformat the imports the way you want them to be using isort -rc -m x . (x being one of the different multi-line modes isort offers for imports)
1reaction
bersbersberscommented, Mar 7, 2019

Just adding here that autoflake is also unable to detect single-line imports with parentheses:

from re import sub
from re import (subn)

First line is detected, second one is not. This will surely be fixed by a fix of this issue, but until then, maybe (just maybe) it makes sense to tackle it independently in the meantime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle multiline import-from statements · Issue #8 - GitHub
Reformat every import into one line: isort -rc -sl . Use autoflake to remove unused imports; Reformat the imports the way you want...
Read more >
python - Is there a recommended format for multi-line imports?
Te real statement is from data.forms import AddressEmbeddedField, PhoneEmbeddedField, MailEmbeddedField, \ WebEmbeddedField but don't want ...
Read more >
Running Multi-Line Shell Code at Once From Single Prompt
This is a useful technique that divides lengthy commands into readable statements contained within the shell session's window. Backslashes also ...
Read more >
PEP 328 – Imports: Multi-Line and Absolute/Relative
The import statement has two problems: Long import statements can be difficult to write, requiring various contortions to fit Pythonic style ...
Read more >
Importing multiline cells from csv file into excel - Super User
fix the bug in the Text Import Wizard so that it correctly handles multiline values. However there are some workarounds. My favourite: Open...
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