From 93576fbd8087b31ab5befff6d5c5c9e9190589d4 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Sun, 26 May 2024 00:55:19 +0800 Subject: [PATCH] Use ssh for pre-commit initial --- .pre-commit-config.yaml | 4 ++-- pypika/terms.py | 33 +++++++++++++++------------------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3232a4d0..f2b4b475 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ default_stages: [commit] fail_fast: false repos: - - repo: https://github.com/pre-commit/pre-commit-hooks + - repo: git@github.com:pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - id: trailing-whitespace @@ -19,7 +19,7 @@ repos: - id: check-yaml - id: debug-statements - - repo: https://github.com/psf/black + - repo: git@github.com:psf/black rev: 23.9.1 hooks: - id: black diff --git a/pypika/terms.py b/pypika/terms.py index ce7aed65..9cc305eb 100644 --- a/pypika/terms.py +++ b/pypika/terms.py @@ -75,10 +75,10 @@ def wrap_constant( """ - if isinstance(val, Node): - return val if val is None: return NullValue() + if isinstance(val, Node): + return val if isinstance(val, list): return Array(*val) if isinstance(val, tuple): @@ -94,10 +94,10 @@ def wrap_json( ) -> Union["Term", "QueryBuilder", "Interval", "NullValue", "ValueWrapper", "JSON"]: from .queries import QueryBuilder - if isinstance(val, (Term, QueryBuilder, Interval)): - return val if val is None: return NullValue() + if isinstance(val, (Term, QueryBuilder, Interval)): + return val if isinstance(val, (str, int, bool)): wrapper_cls = wrapper_cls or ValueWrapper return wrapper_cls(val) @@ -316,12 +316,9 @@ def get_sql(self, **kwargs: Any) -> str: return ":{placeholder}".format(placeholder=self.placeholder) -class NamedParameter(Parameter): +class NamedParameter(NumericParameter): """Named style, e.g. ...WHERE name=:name""" - def get_sql(self, **kwargs: Any) -> str: - return ":{placeholder}".format(placeholder=self.placeholder) - class FormatParameter(Parameter): """ANSI C printf format codes, e.g. ...WHERE name=%s""" @@ -365,6 +362,8 @@ def get_value_sql(self, **kwargs: Any) -> str: @classmethod def get_formatted_value(cls, value: Any, **kwargs): + if value is None: + return "null" quote_char = kwargs.get("secondary_quote_char") or "" # FIXME escape values @@ -381,8 +380,6 @@ def get_formatted_value(cls, value: Any, **kwargs): return str.lower(str(value)) if isinstance(value, uuid.UUID): return cls.get_formatted_value(str(value), **kwargs) - if value is None: - return "null" return str(value) def get_sql(self, quote_char: Optional[str] = None, secondary_quote_char: str = "'", **kwargs: Any) -> str: @@ -485,20 +482,19 @@ def __init__(self, alias: Optional[str] = None) -> None: class Criterion(Term): - def __and__(self, other: Any) -> "ComplexCriterion": + def _compare(self, comparator: Comparator, other: Any) -> "ComplexCriterion": if isinstance(other, EmptyCriterion): return self - return ComplexCriterion(Boolean.and_, self, other) + return ComplexCriterion(comparator, self, other) + + def __and__(self, other: Any) -> "ComplexCriterion": + return self._compare(Boolean.and_, other) def __or__(self, other: Any) -> "ComplexCriterion": - if isinstance(other, EmptyCriterion): - return self - return ComplexCriterion(Boolean.or_, self, other) + return self._compare(Boolean.or_, other) def __xor__(self, other: Any) -> "ComplexCriterion": - if isinstance(other, EmptyCriterion): - return self - return ComplexCriterion(Boolean.xor_, self, other) + return self._compare(Boolean.xor_, other) @staticmethod def any(terms: Iterable[Term] = ()) -> "EmptyCriterion": @@ -551,6 +547,7 @@ def __init__( if isinstance(table, str): # avoid circular import at load time from pypika.queries import Table + table = Table(table) self.table = table