Skip to content

Commit cd87229

Browse files
style: apply ruff format to src/schemaforge/parsers/scala_parser.py
1 parent f00eea1 commit cd87229

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/schemaforge/parsers/scala_parser.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Parses Scala case class definitions suitable for Doobie, Quill,
44
or Slick into the internal schema representation.
55
"""
6+
67
from __future__ import annotations
78

89
import re
@@ -12,16 +13,14 @@
1213

1314
# Regex: extract case class
1415
_CASE_CLASS_RE = re.compile(
15-
r'(?:@(?:Entity|Table|Mapped)\s*(?:\([^)]*\))?\s*)?'
16-
r'(?:case\s+)?class\s+(\w+)'
17-
r'(?:\s*\(((?:[^()]|\([^()]*\))*)\))',
16+
r"(?:@(?:Entity|Table|Mapped)\s*(?:\([^)]*\))?\s*)?"
17+
r"(?:case\s+)?class\s+(\w+)"
18+
r"(?:\s*\(((?:[^()]|\([^()]*\))*)\))",
1819
re.MULTILINE,
1920
)
2021

2122
# Regex: extract field from case class parameter list
22-
_FIELD_RE = re.compile(
23-
r'\s*(\w+)\s*:\s*([^=,]+)(?:\s*=\s*([^,]+))?\s*,?\s*'
24-
)
23+
_FIELD_RE = re.compile(r"\s*(\w+)\s*:\s*([^=,]+)(?:\s*=\s*([^,]+))?\s*,?\s*")
2524

2625
# Map Scala types to ColumnType
2726
_SCALA_TYPE_MAP: dict[str, ColumnType] = {
@@ -92,8 +91,9 @@ def _parse_default(value_str: str) -> Any:
9291
return None
9392

9493
# Quoted strings
95-
if (val.startswith('"') and val.endswith('"')) or \
96-
(val.startswith('"""') and val.endswith('"""')):
94+
if (val.startswith('"') and val.endswith('"')) or (
95+
val.startswith('"""') and val.endswith('"""')
96+
):
9797
inner = val.strip('"')
9898
# Handle interpolation: s"..."
9999
idx = inner.find("$")
@@ -143,7 +143,9 @@ def parse(self, text: str) -> Schema:
143143
fields = _FIELD_RE.findall(params_str)
144144

145145
for field_name, field_type, default_str in fields:
146-
col = self._field_to_column(field_name, field_type.strip(), default_str.strip())
146+
col = self._field_to_column(
147+
field_name, field_type.strip(), default_str.strip()
148+
)
147149
if col:
148150
table.columns.append(col)
149151

@@ -152,7 +154,9 @@ def parse(self, text: str) -> Schema:
152154

153155
return schema
154156

155-
def _field_to_column(self, name: str, raw_type: str, default_str: str) -> Column | None:
157+
def _field_to_column(
158+
self, name: str, raw_type: str, default_str: str
159+
) -> Column | None:
156160
"""Convert a Scala field to a Column IR."""
157161
clean_type, is_optional = _clean_scala_type(raw_type)
158162

0 commit comments

Comments
 (0)