@@ -196,7 +196,7 @@ def process(
196196 first_comment_index_end = index - 1
197197
198198 was_in_quote = bool (in_quote )
199- if ( not stripped_line .startswith ("#" ) or in_quote ) and '"' in line or "'" in line :
199+ if not is_module_dunder ( stripped_line ) and ( not stripped_line .startswith ("#" ) or in_quote ) and ( '"' in line or "'" in line ) :
200200 char_index = 0
201201 if first_comment_index_start == - 1 and (
202202 line .startswith ('"' ) or line .startswith ("'" )
@@ -290,14 +290,24 @@ def process(
290290 ):
291291 import_section += line
292292 elif is_module_dunder (stripped_line ):
293- import_section += line
293+ # Handle module-level dunders.
294+ dunder_statement = line
295+ if stripped_line .endswith (("\\ " , "[" , '= """' , "= '''" )):
296+ # Handle multiline module dunder assignments.
297+ while stripped_line and not stripped_line .endswith ("]" ) and stripped_line != '"""' and stripped_line != "'''" :
298+ line = input_stream .readline ()
299+ stripped_line = line .strip ()
300+ dunder_statement += line
301+ import_section += dunder_statement
302+
294303 elif stripped_line .startswith (IMPORT_START_IDENTIFIERS ):
295304 new_indent = line [: - len (line .lstrip ())]
296305 import_statement = line
297306 stripped_line = line .strip ().split ("#" )[0 ]
298307 while stripped_line .endswith ("\\ " ) or (
299308 "(" in stripped_line and ")" not in stripped_line
300309 ):
310+ # Handle multiline import statements.
301311 if stripped_line .endswith ("\\ " ):
302312 while stripped_line and stripped_line .endswith ("\\ " ):
303313 line = input_stream .readline ()
0 commit comments