File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -332,6 +332,18 @@ def foo():
332332 """ ,
333333 )
334334
335+ def test_white_space_pytorch_example (self ) -> None :
336+ config = replace (DEFAULT_CONFIG , preserve_inline_comments = True )
337+ self .assertUsortResult (
338+ """
339+ from package.test_save_load import TestSaveLoad # noqa: F401
340+ """ ,
341+ """
342+ from package.test_save_load import TestSaveLoad # noqa: F401
343+ """ ,
344+ config ,
345+ )
346+
335347 def test_case_insensitive_sorting (self ) -> None :
336348 content = """
337349 import calendar
Original file line number Diff line number Diff line change @@ -258,9 +258,10 @@ def import_to_node(
258258 if config .magic_commas and imp .stem and imp .trailing_comma :
259259 return import_to_node_multi (imp , module )
260260
261- # If preserve_inline_comments is enabled and any item has inline comments,
262- # use multi-line format to preserve them
263- if config .preserve_inline_comments and imp .stem :
261+ # If preserve_inline_comments is enabled and multiple items have inline comments,
262+ # use multi-line format to preserve them. Single-item imports can keep comments
263+ # on the same line.
264+ if config .preserve_inline_comments and imp .stem and len (imp .items ) > 1 :
264265 has_item_comments = any (item .comments .inline for item in imp .items )
265266 if has_item_comments :
266267 return import_to_node_multi (imp , module )
You can’t perform that action at this time.
0 commit comments