Skip to content

Commit 6153f4d

Browse files
committed
Fix the code smell reported by SQ
1 parent 5bcf6c2 commit 6153f4d

3 files changed

Lines changed: 9 additions & 39 deletions

File tree

pydynamodb/sql/dml_sql.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ def __escape_column(self, token: Any) -> str:
135135

136136
def __init__(self, statement: str) -> None:
137137
super().__init__(statement)
138-
self._where_conditions = []
138+
self._parsed_where_conditions = []
139139
self._limit = None
140140
self._consistent_read = False
141141
self._return_consumed_capacity = "NONE"
142142

143143
@property
144144
def where_conditions(self) -> List[Optional[str]]:
145-
return self._where_conditions
145+
return self._parsed_where_conditions
146146

147147
@property
148148
def limit(self) -> int:
@@ -166,18 +166,18 @@ def transform(self) -> Dict[str, Any]:
166166
def _construct_where_conditions(self, where_conditions: List[Any]) -> str:
167167
for condition in where_conditions:
168168
if not isinstance(condition, ParseResults):
169-
self._where_conditions.append(str(condition))
169+
self._parsed_where_conditions.append(str(condition))
170170
else:
171171
function_ = condition.get("function", None)
172172
function_with_op_ = condition.get("function_with_op", None)
173173
if function_:
174174
flatted_func_params = ",".join(condition["function_params"])
175-
self._where_conditions.append(
175+
self._parsed_where_conditions.append(
176176
"%s(%s)" % (function_, flatted_func_params)
177177
)
178178
elif function_with_op_:
179179
flatted_func_params = ",".join(condition["function_params"])
180-
self._where_conditions.append(
180+
self._parsed_where_conditions.append(
181181
"%s(%s) %s %s"
182182
% (
183183
function_with_op_,
@@ -191,7 +191,7 @@ def _construct_where_conditions(self, where_conditions: List[Any]) -> str:
191191
flatted_where = " ".join(
192192
str(c) for c in flatten_list(where_conditions_)
193193
)
194-
self._where_conditions.append(flatted_where)
194+
self._parsed_where_conditions.append(flatted_where)
195195

196196
return "WHERE %s" % " ".join(self.where_conditions)
197197

pydynamodb/sql/json_parser.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,6 @@
99
# members optional in array and object collections
1010
#
1111
# Updated 9 Aug 2016 - use more current pyparsing constructs/idioms
12-
#
13-
'''
14-
json_bnf = """
15-
object
16-
{ members }
17-
{}
18-
members
19-
string : value
20-
members , string : value
21-
array
22-
[ elements ]
23-
[]
24-
elements
25-
value
26-
elements , value
27-
value
28-
string
29-
number
30-
object
31-
array
32-
true
33-
false
34-
null
35-
"""
36-
'''
3712

3813
import pyparsing as pp
3914
from pyparsing import pyparsing_common as ppc
@@ -61,11 +36,6 @@ def make_keyword(kwd_str, kwd_value):
6136
jsonValue = pp.Forward().set_name("jsonValue")
6237

6338
jsonElements = pp.DelimitedList(jsonValue).set_name(None)
64-
# jsonArray = pp.Group(LBRACK + pp.Optional(jsonElements, []) + RBRACK)
65-
# jsonValue << (
66-
# jsonString | jsonNumber | pp.Group(jsonObject) | jsonArray | TRUE | FALSE | NULL
67-
# )
68-
# memberDef = pp.Group(jsonString + COLON + jsonValue).set_name("jsonMember")
6939

7040
jsonArray = pp.Group(
7141
LBRACK + pp.Optional(jsonElements) + RBRACK, aslist=RETURN_PYTHON_COLLECTIONS

pydynamodb/sql/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .dml_update import DmlUpdate
1313
from .dml_delete import DmlDelete
1414
from .util_sql import UtilListTables, UtilDescTable
15-
from typing import Any, Dict, Tuple
15+
from typing import Any, Dict, Tuple, Type, Optional
1616

1717
_logger = logging.getLogger(__name__) # type: ignore
1818

@@ -71,8 +71,8 @@ def parser(self) -> Base:
7171

7272
return self._parser
7373

74-
def _get_parse_class(self) -> Base:
75-
_parse_class = None
74+
def _get_parse_class(self) -> Optional[Type[Base]]:
75+
_parse_class: Optional[Type[Base]] = None
7676
if (
7777
self.query_type == QueryType.CREATE
7878
or self.query_type == QueryType.CREATE_GLOBAL

0 commit comments

Comments
 (0)