Skip to content

Commit 65ea82d

Browse files
committed
remove deprecated AST node types
1 parent 2aa571a commit 65ea82d

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

qastle/linq_util.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,26 @@ def visit_Call(self, node):
122122
if function_name == 'Where':
123123
if len(args) != 1:
124124
raise SyntaxError('Where() call must have exactly one argument')
125-
if isinstance(args[0], ast.Str):
126-
args[0] = unwrap_ast(ast.parse(args[0].s))
125+
if isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
126+
args[0] = unwrap_ast(ast.parse(args[0].value))
127127
if not isinstance(args[0], ast.Lambda):
128128
raise SyntaxError('Where() call argument must be a lambda')
129129
return Where(source=self.visit(source),
130130
predicate=self.visit(args[0]))
131131
elif function_name == 'Select':
132132
if len(args) != 1:
133133
raise SyntaxError('Select() call must have exactly one argument')
134-
if isinstance(args[0], ast.Str):
135-
args[0] = unwrap_ast(ast.parse(args[0].s))
134+
if isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
135+
args[0] = unwrap_ast(ast.parse(args[0].value))
136136
if not isinstance(args[0], ast.Lambda):
137137
raise SyntaxError('Select() call argument must be a lambda')
138138
return Select(source=self.visit(source),
139139
selector=self.visit(args[0]))
140140
elif function_name == 'SelectMany':
141141
if len(args) != 1:
142142
raise SyntaxError('SelectMany() call must have exactly one argument')
143-
if isinstance(args[0], ast.Str):
144-
args[0] = unwrap_ast(ast.parse(args[0].s))
143+
if isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
144+
args[0] = unwrap_ast(ast.parse(args[0].value))
145145
if not isinstance(args[0], ast.Lambda):
146146
raise SyntaxError('SelectMany() call argument must be a lambda')
147147
return SelectMany(source=self.visit(source),
@@ -166,8 +166,8 @@ def visit_Call(self, node):
166166
if len(args) != 2:
167167
raise SyntaxError('Aggregate() call must have exactly two arguments; found'
168168
+ str(len(args)))
169-
if isinstance(args[1], ast.Str):
170-
args[1] = unwrap_ast(ast.parse(args[1].s))
169+
if isinstance(args[1], ast.Constant) and isinstance(args[1].value, str):
170+
args[1] = unwrap_ast(ast.parse(args[1].value))
171171
if not isinstance(args[1], ast.Lambda):
172172
raise SyntaxError('Second Aggregate() call argument must be a lambda')
173173
return Aggregate(source=self.visit(source),
@@ -192,17 +192,17 @@ def visit_Call(self, node):
192192
elif function_name == 'All':
193193
if len(args) != 1:
194194
raise SyntaxError('All() call must have exactly one argument')
195-
if isinstance(args[0], ast.Str):
196-
args[0] = unwrap_ast(ast.parse(args[0].s))
195+
if isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
196+
args[0] = unwrap_ast(ast.parse(args[0].value))
197197
if not isinstance(args[0], ast.Lambda):
198198
raise SyntaxError('All() call argument must be a lambda')
199199
return All(source=self.visit(source),
200200
predicate=self.visit(args[0]))
201201
elif function_name == 'Any':
202202
if len(args) != 1:
203203
raise SyntaxError('Any() call must have exactly one argument')
204-
if isinstance(args[0], ast.Str):
205-
args[0] = unwrap_ast(ast.parse(args[0].s))
204+
if isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
205+
args[0] = unwrap_ast(ast.parse(args[0].value))
206206
if not isinstance(args[0], ast.Lambda):
207207
raise SyntaxError('Any() call argument must be a lambda')
208208
return Any(source=self.visit(source),
@@ -218,17 +218,17 @@ def visit_Call(self, node):
218218
elif function_name == 'OrderBy':
219219
if len(args) != 1:
220220
raise SyntaxError('OrderBy() call must have exactly one argument')
221-
if isinstance(args[0], ast.Str):
222-
args[0] = unwrap_ast(ast.parse(args[0].s))
221+
if isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
222+
args[0] = unwrap_ast(ast.parse(args[0].value))
223223
if not isinstance(args[0], ast.Lambda):
224224
raise SyntaxError('OrderBy() call argument must be a lambda')
225225
return OrderBy(source=self.visit(source),
226226
key_selector=self.visit(args[0]))
227227
elif function_name == 'OrderByDescending':
228228
if len(args) != 1:
229229
raise SyntaxError('OrderByDescending() call must have exactly one argument')
230-
if isinstance(args[0], ast.Str):
231-
args[0] = unwrap_ast(ast.parse(args[0].s))
230+
if isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
231+
args[0] = unwrap_ast(ast.parse(args[0].value))
232232
if not isinstance(args[0], ast.Lambda):
233233
raise SyntaxError('OrderByDescending() call argument must be a lambda')
234234
return OrderByDescending(source=self.visit(source),

qastle/transform.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ def visit_Name(self, node):
6464
def visit_Constant(self, node):
6565
return repr(node.value)
6666

67-
def visit_Num(self, node):
68-
return repr(node.n)
69-
70-
def visit_Str(self, node):
71-
return repr(node.s)
72-
73-
def visit_NameConstant(self, node):
74-
return repr(node.value)
75-
7667
@staticmethod
7768
def make_composite_node_string(node_type, *fields):
7869
return '(' + node_type + ''.join([' ' + field for field in fields]) + ')'
@@ -113,11 +104,11 @@ def visit_IfExp(self, node):
113104

114105
def visit_UnaryOp(self, node):
115106
if (hasattr(ast, 'Constant') and isinstance(node.operand, ast.Constant)
116-
or isinstance(node.operand, ast.Num)):
107+
or (isinstance(node.operand, ast.Constant) and isinstance(node.operand.value, (int, float, complex)))):
117108
if isinstance(node.op, ast.UAdd):
118109
return self.visit(node.operand)
119110
elif isinstance(node.op, ast.USub):
120-
return self.visit(ast.Num(n=-node.operand.n))
111+
return self.visit(ast.Constant(value=-node.operand.value))
121112
return self.make_composite_node_string(op_strings[type(node.op)],
122113
self.visit(node.operand))
123114

@@ -302,9 +293,9 @@ def composite(self, children):
302293
elif node_type == 'attr':
303294
if len(fields) != 2:
304295
raise SyntaxError('Attribute node must have two fields; found ' + str(len(fields)))
305-
if not isinstance(fields[1], ast.Str):
296+
if not (isinstance(fields[1], ast.Constant) and isinstance(fields[1].value, str)):
306297
raise SyntaxError('Attribute name must be a string; found ' + str(type(fields[1])))
307-
return ast.Attribute(value=fields[0], attr=fields[1].s, ctx=ast.Load())
298+
return ast.Attribute(value=fields[0], attr=fields[1].value, ctx=ast.Load())
308299

309300
elif node_type == 'subscript':
310301
if len(fields) != 2:

0 commit comments

Comments
 (0)