Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit 3a8818a

Browse files
committed
Add Python SpacesStyle
1 parent 88bb0b8 commit 3a8818a

4 files changed

Lines changed: 77 additions & 2 deletions

File tree

rewrite/rewrite/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .visitor import Cursor, TreeVisitor
1212
from .parser import *
1313
from .result import *
14+
from .style import *
1415

1516
__all__ = [
1617
'Checksum',
@@ -36,5 +37,8 @@
3637
'ParserBuilder',
3738
'ParseExceptionResult',
3839
'Result',
39-
'SourceFile'
40-
]
40+
'SourceFile',
41+
42+
# Style
43+
'Style',
44+
]

rewrite/rewrite/python/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .parser import *
55
from .visitor import *
66
from .markers import *
7+
from .style import *
78
from .format import *
89

910
__all__ = [
@@ -53,6 +54,10 @@
5354
'VariableScope',
5455
'YieldFrom',
5556

57+
# Style
58+
'PythonStyle',
59+
'SpacesStyle',
60+
5661
# Formatter
5762
'AutoFormat',
5863
]

rewrite/rewrite/python/style.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from dataclasses import dataclass
2+
3+
from ..style import Style
4+
5+
6+
class PythonStyle(Style):
7+
pass
8+
9+
10+
@dataclass(frozen=True)
11+
class SpacesStyle(PythonStyle):
12+
@dataclass(frozen=True)
13+
class BeforeParentheses:
14+
method_call_parentheses: bool
15+
method_parentheses: bool
16+
left_bracket: bool
17+
18+
@dataclass(frozen=True)
19+
class AroundOperators:
20+
assignment: bool
21+
equality: bool
22+
relational: bool
23+
bitwise: bool
24+
additive: bool
25+
multiplicative: bool
26+
shift: bool
27+
power: bool
28+
eq_in_named_parameter: bool
29+
eq_in_keyword_argument: bool
30+
31+
@dataclass(frozen=True)
32+
class Within:
33+
brackets: bool
34+
method_parentheses: bool
35+
empty_method_parentheses: bool
36+
method_call_parentheses: bool
37+
empty_method_call_parentheses: bool
38+
braces: bool
39+
40+
@dataclass(frozen=True)
41+
class Other:
42+
before_comma: bool
43+
after_comma: bool
44+
before_semicolon: bool
45+
before_for_semicolon: bool
46+
before_colon: bool
47+
after_colon: bool
48+
before_backslash: bool
49+
before_hash: bool
50+
after_hash: bool
51+
52+
beforeParentheses: BeforeParentheses
53+
aroundOperators: AroundOperators
54+
within: Within
55+
other: Other

rewrite/rewrite/style.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from __future__ import annotations
2+
3+
from typing import Protocol
4+
5+
6+
class Style(Protocol):
7+
def merge(self, lower_precedence: Style) -> Style:
8+
...
9+
10+
def apply_defaults(self) -> Style:
11+
return self

0 commit comments

Comments
 (0)