diff --git a/rewrite/rewrite/python/format/spaces_visitor.py b/rewrite/rewrite/python/format/spaces_visitor.py index 04420912..164cccb5 100644 --- a/rewrite/rewrite/python/format/spaces_visitor.py +++ b/rewrite/rewrite/python/format/spaces_visitor.py @@ -413,7 +413,8 @@ def _process_element(index, arg, args_size, use_space): elif cl.kind == CollectionLiteral.Kind.LIST: _space_style = self._style.within.brackets elif cl.kind == CollectionLiteral.Kind.TUPLE: - _space_style = self._style.within.brackets if self.cursor.first_enclosing(ExpressionTypeTree) else False + _space_style = False + cl = cl.padding.with_elements(cl.padding.elements.with_before(Space.EMPTY)) cl = cl.padding.with_elements( cl.padding.elements.padding.with_elements( diff --git a/rewrite/rewrite/python/format/tabs_and_indents_visitor.py b/rewrite/rewrite/python/format/tabs_and_indents_visitor.py index 9b43aa0f..f62f3cef 100644 --- a/rewrite/rewrite/python/format/tabs_and_indents_visitor.py +++ b/rewrite/rewrite/python/format/tabs_and_indents_visitor.py @@ -235,6 +235,11 @@ def visit_right_padded(self, right: Optional[JRightPadded[T]], right = right.with_markers(right.markers.compute_by_type(TrailingComma, lambda t: trailing_comma)) elif loc == JRightPadded.Location.ANNOTATION_ARGUMENT: raise NotImplementedError("Annotation argument not implemented") + elif loc == PyRightPadded.Location.MULTI_IMPORT_NAME: + self.cursor.parent_or_throw.put_message("indent_type", self.IndentType.INDENT) + elem = self.visit_and_cast(elem, J, p) + self.cursor.parent_or_throw.put_message("indent_type", self.IndentType.ALIGN) + after = self.visit_space(right.after, loc.after_location, p) else: elem = self.visit_and_cast(elem, J, p) after = self.visit_space(right.after, loc.after_location, p) diff --git a/rewrite/tests/python/all/format/full_formatter_test.py b/rewrite/tests/python/all/format/full_formatter_test.py index b2f4d4e6..de726c52 100644 --- a/rewrite/tests/python/all/format/full_formatter_test.py +++ b/rewrite/tests/python/all/format/full_formatter_test.py @@ -9,8 +9,9 @@ def test_full_formatter(): """\ from typing import Tuple from dataclasses import dataclass - import os,sys - + from os import ( + path, system,environ + ) @dataclass class Test: @@ -57,6 +58,12 @@ def nested_structures(self): 3],"other":{ "nested":4}} + def tuples(self): + a= ( + 1, 2, 3 + ) + b= (1, 2, 3) + def operators_test(self): a, b, c,d, e, f = 1, 2, 3, 4, 5, 6 a=1+2 @@ -117,7 +124,9 @@ def first_method(self): pass """\ from typing import Tuple from dataclasses import dataclass - import os, sys + from os import ( + path, system, environ + ) @dataclass @@ -165,6 +174,12 @@ def nested_structures(self): 3], "other": { "nested": 4}} + def tuples(self): + a = ( + 1, 2, 3 + ) + b = (1, 2, 3) + def operators_test(self): a, b, c, d, e, f = 1, 2, 3, 4, 5, 6 a = 1 + 2 diff --git a/rewrite/tests/python/all/format/spaces/array_spaces_test.py b/rewrite/tests/python/all/format/spaces/array_spaces_test.py index 1e975142..797c04f0 100644 --- a/rewrite/tests/python/all/format/spaces/array_spaces_test.py +++ b/rewrite/tests/python/all/format/spaces/array_spaces_test.py @@ -163,3 +163,19 @@ def test_spaces_within_array_access_brackets_slice_with_expressions(): .with_recipe(from_visitor(SpacesVisitor(style))) ) + +def test_spaces_with_tuple(): + style = IntelliJ.spaces() + rewrite_run( + # language=python + python( + """ + a= (1, 2, 3) + """, + """ + a = (1, 2, 3) + """ + ), + spec=RecipeSpec() + .with_recipe(from_visitor(SpacesVisitor(style))) + ) diff --git a/rewrite/tests/python/all/format/tabs_and_indents_visitor_test.py b/rewrite/tests/python/all/format/tabs_and_indents_visitor_test.py index 5af475f3..1d7d5dd1 100644 --- a/rewrite/tests/python/all/format/tabs_and_indents_visitor_test.py +++ b/rewrite/tests/python/all/format/tabs_and_indents_visitor_test.py @@ -1070,3 +1070,23 @@ def long_function_name(self): from_visitor(TabsAndIndentsVisitor(style)) ) ) + +def test_import_with_tuple(): + style = IntelliJ.tabs_and_indents() + rewrite_run( + # language=python + python( + """ + from os import ( + path, system, environ + ) + """, + """ + from os import ( + path, system, environ + ) + """ + ), + spec=RecipeSpec() + .with_recipe(from_visitor(TabsAndIndentsVisitor(style))) + )