New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SyntaxError rewriting specific combination of imports and defs #490
Comments
line was combined in Lines 887 to 890 in fff90d4
But I am not sure is a good idea to not join the line here, beacause it will cause the line number not matched with pycodestyle check result. If I split and get first line in a = 1
from csv import (
reader,
writer,
)
import os Maybe we should change the way to check |
Or we do something like Lines 880 to 886 in fff90d4
when meet |
this also works: diff --git a/autopep8.py b/autopep8.py
index 01b90d6..05b818c 100755
--- a/autopep8.py
+++ b/autopep8.py
@@ -1409,7 +1409,10 @@ def get_module_imports_on_top_of_file(source, import_line_index):
return line and (line[0] == '"' or line[0] == "'")
def is_future_import(line):
- nodes = ast.parse(line)
+ try:
+ nodes = ast.parse(line)
+ except SyntaxError:
+ return False
for n in nodes.body:
if isinstance(n, ast.ImportFrom) and n.module == '__future__':
return True it assumes that a moved import is never a |
There some more complicated case, like from __future__ import (
absolute_import,
print_function,
)
a = 1
import os
|
Python Code
Command Line and Configuration
Command Line
Your Environment
Analysis
it appears to be happening while checking for
__future__
imports -- the import reordering code is combining afrom
import line with thedef
line causing the "check if this import is a__future__
import" code to parse too muchThe text was updated successfully, but these errors were encountered: