Skip to content

Commit 531e8ff

Browse files
author
Peng Ren
committed
Refactor code
1 parent c8de94a commit 531e8ff

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

pymongosql/sql/handler.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,6 @@ class ParseResult:
5050
offset_value: Optional[int] = None
5151

5252
# Factory methods for different use cases
53-
@classmethod
54-
def for_expression(
55-
cls,
56-
filter_conditions: Dict[str, Any] = None,
57-
has_errors: bool = False,
58-
error_message: str = None,
59-
) -> "ParseResult":
60-
"""Create ParseResult for expression parsing"""
61-
return cls(
62-
filter_conditions=filter_conditions or {},
63-
has_errors=has_errors,
64-
error_message=error_message,
65-
)
66-
6753
@classmethod
6854
def for_visitor(cls) -> "ParseResult":
6955
"""Create ParseResult for visitor parsing"""
@@ -288,14 +274,14 @@ def handle_expression(self, ctx: Any) -> ParseResult:
288274
operator=operator,
289275
)
290276

291-
return ParseResult.for_expression(filter_conditions=mongo_filter)
277+
return ParseResult(filter_conditions=mongo_filter)
292278

293279
except Exception as e:
294280
processing_time = (time.time() - start_time) * 1000
295281
self._log_operation_error(
296282
"comparison_parsing", ctx, operation_id, processing_time, e
297283
)
298-
return ParseResult.for_expression(has_errors=True, error_message=str(e))
284+
return ParseResult(has_errors=True, error_message=str(e))
299285

300286
def _build_mongo_filter(
301287
self, field_name: str, operator: str, value: Any
@@ -487,14 +473,14 @@ def handle_expression(self, ctx: Any) -> ParseResult:
487473
processed_count=len(processed_operands),
488474
)
489475

490-
return ParseResult.for_expression(filter_conditions=mongo_filter)
476+
return ParseResult(filter_conditions=mongo_filter)
491477

492478
except Exception as e:
493479
processing_time = (time.time() - start_time) * 1000
494480
self._log_operation_error(
495481
"logical_parsing", ctx, operation_id, processing_time, e
496482
)
497-
return ParseResult.for_expression(has_errors=True, error_message=str(e))
483+
return ParseResult(has_errors=True, error_message=str(e))
498484

499485
def _process_operands(self, operands: List[Any]) -> List[Dict[str, Any]]:
500486
"""Process operands and return processed filters"""
@@ -640,14 +626,14 @@ def handle_expression(self, ctx: Any) -> ParseResult:
640626
function_name=function_name,
641627
)
642628

643-
return ParseResult.for_expression(filter_conditions=mongo_filter)
629+
return ParseResult(filter_conditions=mongo_filter)
644630

645631
except Exception as e:
646632
processing_time = (time.time() - start_time) * 1000
647633
self._log_operation_error(
648634
"function_parsing", ctx, operation_id, processing_time, e
649635
)
650-
return ParseResult.for_expression(has_errors=True, error_message=str(e))
636+
return ParseResult(has_errors=True, error_message=str(e))
651637

652638
def _is_function_context(self, ctx: Any) -> bool:
653639
"""Check if context is a function call"""

0 commit comments

Comments
 (0)