| 1 |
"""A visitor to validate an AST object.""" |
| 2 |
|
| 3 |
from pypy.interpreter.error import oefmt |
| 4 |
from pypy.interpreter.astcompiler import ast |
| 5 |
from rpython.tool.pairtype import pair, pairtype |
| 6 |
from pypy.interpreter.baseobjspace import W_Root |
| 7 |
|
| 8 |
|
| 9 |
def validate_ast(space, node): |
| 10 |
node.walkabout(AstValidator(space)) |
| 11 |
|
| 12 |
|
| 13 |
class ValidationError(Exception): |
| 14 |
|
| 15 |
def __init__(self, message): |
| 16 |
self.message = message |
| 17 |
|
| 18 |
def __str__(self): |
| 19 |
return self.message |
| 20 |
|
| 21 |
class ValidationTypeError(ValidationError): |
| 22 |
|
| 23 |
pass |
| 24 |
|
| 25 |
|
| 26 |
def expr_context_name(ctx): |
| 27 |
if not 1 <= ctx <= len(ast.expr_context_to_class): |
| 28 |
return '??' |
| 29 |
return ast.expr_context_to_class[ctx - 1].__name__[1:] |
| 30 |
|
| 31 |
def _check_context(expected_ctx, actual_ctx): |
| 32 |
if expected_ctx != actual_ctx: |
| 33 |
raise ValidationError( |
| 34 |
"expression must have %s context but has %s instead" % |
| 35 |
(expr_context_name(expected_ctx), expr_context_name(actual_ctx))) |
| 36 |
|
| 37 |
|
| 38 |
class __extend__(ast.AST): |
| 39 |
|
| 40 |
def check_context(self, visitor, ctx): |
| 41 |
raise AssertionError("should only be on expressions") |
| 42 |
|
| 43 |
def walkabout_with_ctx(self, visitor, ctx): |
| 44 |
self.walkabout(visitor) |
| 45 |
|
| 46 |
|
| 47 |
class __extend__(ast.expr): |
| 48 |
|
| 49 |
def check_context(self, visitor, ctx): |
| 50 |
if ctx != ast.Load: |
| 51 |
raise ValidationError( |
| 52 |
"expression which can't be assigned to in %s context" % |
| 53 |
expr_context_name(ctx)) |
| 54 |
|
| 55 |
|
| 56 |
class __extend__(ast.Name): |
| 57 |
|
| 58 |
def check_context(self, visitor, ctx): |
| 59 |
_check_context(ctx, self.ctx) |
| 60 |
|
| 61 |
|
| 62 |
class __extend__(ast.List): |
| 63 |
|
| 64 |
def check_context(self, visitor, ctx): |
| 65 |
_check_context(ctx, self.ctx) |
| 66 |
|
| 67 |
def walkabout_with_ctx(self, visitor, ctx): |
| 68 |
visitor._validate_exprs(self.elts, ctx) |
| 69 |
|
| 70 |
|
| 71 |
class __extend__(ast.Tuple): |
| 72 |
|
| 73 |
def check_context(self, visitor, ctx): |
| 74 |
_check_context(ctx, self.ctx) |
| 75 |
|
| 76 |
def walkabout_with_ctx(self, visitor, ctx): |
| 77 |
visitor._validate_exprs(self.elts, ctx) |
| 78 |
|
| 79 |
|
| 80 |
class __extend__(ast.Starred): |
| 81 |
|
| 82 |
def check_context(self, visitor, ctx): |
| 83 |
_check_context(ctx, self.ctx) |
| 84 |
|
| 85 |
def walkabout_with_ctx(self, visitor, ctx): |
| 86 |
visitor._validate_expr(self.value, ctx) |
| 87 |
|
| 88 |
|
| 89 |
class __extend__(ast.Subscript): |
| 90 |
|
| 91 |
def check_context(self, visitor, ctx): |
| 92 |
_check_context(ctx, self.ctx) |
| 93 |
|
| 94 |
|
| 95 |
class __extend__(ast.Attribute): |
| 96 |
|
| 97 |
def check_context(self, visitor, ctx): |
| 98 |
_check_context(ctx, self.ctx) |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
def validate_constant(space, w_obj): |
| 103 |
if space.is_w(w_obj, space.w_None): |
| 104 |
return |
| 105 |
if space.is_w(w_obj, space.w_Ellipsis): |
| 106 |
return |
| 107 |
w_type = space.type(w_obj) |
| 108 |
if w_type in (space.w_int, |
| 109 |
space.w_float, |
| 110 |
space.w_complex, |
| 111 |
space.w_bool, |
| 112 |
space.w_unicode, |
| 113 |
space.w_bytes): |
| 114 |
return |
| 115 |
if w_type in (space.w_tuple, space.w_frozenset): |
| 116 |
for w_item in space.unpackiterable(w_obj): |
| 117 |
validate_constant(space, w_item) |
| 118 |
return |
| 119 |
raise ValidationTypeError("got an invalid type in Constant: %s" % |
| 120 |
space.type(w_obj).name) |
| 121 |
|
| 122 |
|
| 123 |
class AstValidator(ast.ASTVisitor): |
| 124 |
def __init__(self, space): |
| 125 |
self.space = space |
| 126 |
|
| 127 |
def _validate_stmts(self, stmts): |
| 128 |
if not stmts: |
| 129 |
return |
| 130 |
for stmt in stmts: |
| 131 |
if not stmt: |
| 132 |
raise ValidationError("None disallowed in statement list") |
| 133 |
stmt.walkabout(self) |
| 134 |
|
| 135 |
def _len(self, node): |
| 136 |
if node is None: |
| 137 |
return 0 |
| 138 |
return len(node) |
| 139 |
|
| 140 |
def _validate_expr(self, expr, ctx=ast.Load): |
| 141 |
expr.check_context(self, ctx) |
| 142 |
expr.walkabout_with_ctx(self, ctx) |
| 143 |
|
| 144 |
def _validate_exprs(self, exprs, ctx=ast.Load, null_ok=False): |
| 145 |
if not exprs: |
| 146 |
return |
| 147 |
for expr in exprs: |
| 148 |
if expr: |
| 149 |
self._validate_expr(expr, ctx) |
| 150 |
elif not null_ok: |
| 151 |
raise ValidationError("None disallowed in expression list") |
| 152 |
|
| 153 |
def _validate_body(self, body, owner): |
| 154 |
self._validate_nonempty_seq(body, "body", owner) |
| 155 |
self._validate_stmts(body) |
| 156 |
|
| 157 |
def _validate_nonempty_seq(self, seq, what, owner): |
| 158 |
if not seq: |
| 159 |
raise ValidationError("empty %s on %s" % (what, owner)) |
| 160 |
|
| 161 |
def _validate_nonempty_seq_s(self, seq, what, owner): |
| 162 |
if not seq: |
| 163 |
raise ValidationError("empty %s on %s" % (what, owner)) |
| 164 |
|
| 165 |
def _validate_name(self, name): |
| 166 |
if name in ("None", "True", "False"): |
| 167 |
raise ValidationError("identifier field can't represent '%s' constant" % name) |
| 168 |
|
| 169 |
def visit_Interactive(self, node): |
| 170 |
self._validate_stmts(node.body) |
| 171 |
|
| 172 |
def visit_Module(self, node): |
| 173 |
self._validate_stmts(node.body) |
| 174 |
|
| 175 |
def visit_Expression(self, node): |
| 176 |
self._validate_expr(node.body) |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
def visit_arg(self, node): |
| 181 |
if node.annotation: |
| 182 |
self._validate_expr(node.annotation) |
| 183 |
|
| 184 |
def visit_arguments(self, node): |
| 185 |
self.visit_sequence(node.posonlyargs) |
| 186 |
self.visit_sequence(node.args) |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
self.visit_sequence(node.kwonlyargs) |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
if self._len(node.defaults) > self._len(node.args) + self._len(node.posonlyargs): |
| 197 |
raise ValidationError("more positional defaults than args on arguments") |
| 198 |
if self._len(node.kw_defaults) != self._len(node.kwonlyargs): |
| 199 |
raise ValidationError("length of kwonlyargs is not the same as " |
| 200 |
"kw_defaults on arguments") |
| 201 |
self._validate_exprs(node.defaults) |
| 202 |
self._validate_exprs(node.kw_defaults, null_ok=True) |
| 203 |
|
| 204 |
def visit_FunctionDef(self, node): |
| 205 |
self._validate_body(node.body, "FunctionDef") |
| 206 |
node.args.walkabout(self) |
| 207 |
self._validate_exprs(node.decorator_list) |
| 208 |
if node.returns: |
| 209 |
self._validate_expr(node.returns) |
| 210 |
|
| 211 |
def visit_AsyncFunctionDef(self, node): |
| 212 |
self._validate_body(node.body, "AsyncFunctionDef") |
| 213 |
node.args.walkabout(self) |
| 214 |
self._validate_exprs(node.decorator_list) |
| 215 |
if node.returns: |
| 216 |
self._validate_expr(node.returns) |
| 217 |
|
| 218 |
def visit_keyword(self, node): |
| 219 |
self._validate_expr(node.value) |
| 220 |
|
| 221 |
def visit_ClassDef(self, node): |
| 222 |
self._validate_body(node.body, "ClassDef") |
| 223 |
self._validate_exprs(node.bases) |
| 224 |
self.visit_sequence(node.keywords) |
| 225 |
self._validate_exprs(node.decorator_list) |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
def visit_Return(self, node): |
| 232 |
if node.value: |
| 233 |
self._validate_expr(node.value) |
| 234 |
|
| 235 |
def visit_Await(self, node): |
| 236 |
self._validate_expr(node.value) |
| 237 |
|
| 238 |
def visit_Delete(self, node): |
| 239 |
self._validate_nonempty_seq(node.targets, "targets", "Delete") |
| 240 |
self._validate_exprs(node.targets, ast.Del) |
| 241 |
|
| 242 |
def visit_Assign(self, node): |
| 243 |
self._validate_nonempty_seq(node.targets, "targets", "Assign") |
| 244 |
self._validate_exprs(node.targets, ast.Store) |
| 245 |
self._validate_expr(node.value) |
| 246 |
|
| 247 |
def visit_AnnAssign(self, node): |
| 248 |
self._validate_expr(node.target, ast.Store) |
| 249 |
self._validate_expr(node.annotation) |
| 250 |
if node.value: |
| 251 |
self._validate_expr(node.value) |
| 252 |
|
| 253 |
def visit_AugAssign(self, node): |
| 254 |
self._validate_expr(node.target, ast.Store) |
| 255 |
self._validate_expr(node.value) |
| 256 |
|
| 257 |
def visit_For(self, node): |
| 258 |
self._validate_expr(node.target, ast.Store) |
| 259 |
self._validate_expr(node.iter) |
| 260 |
self._validate_body(node.body, "For") |
| 261 |
self._validate_stmts(node.orelse) |
| 262 |
|
| 263 |
def visit_AsyncFor(self, node): |
| 264 |
self._validate_expr(node.target, ast.Store) |
| 265 |
self._validate_expr(node.iter) |
| 266 |
self._validate_body(node.body, "AsyncFor") |
| 267 |
self._validate_stmts(node.orelse) |
| 268 |
|
| 269 |
def visit_While(self, node): |
| 270 |
self._validate_expr(node.test) |
| 271 |
self._validate_body(node.body, "While") |
| 272 |
self._validate_stmts(node.orelse) |
| 273 |
|
| 274 |
def visit_If(self, node): |
| 275 |
self._validate_expr(node.test) |
| 276 |
self._validate_body(node.body, "If") |
| 277 |
self._validate_stmts(node.orelse) |
| 278 |
|
| 279 |
def visit_withitem(self, node): |
| 280 |
self._validate_expr(node.context_expr) |
| 281 |
if node.optional_vars: |
| 282 |
self._validate_expr(node.optional_vars, ast.Store) |
| 283 |
|
| 284 |
def visit_With(self, node): |
| 285 |
self._validate_nonempty_seq(node.items, "items", "With") |
| 286 |
self.visit_sequence(node.items) |
| 287 |
self._validate_body(node.body, "With") |
| 288 |
|
| 289 |
def visit_AsyncWith(self, node): |
| 290 |
self._validate_nonempty_seq(node.items, "items", "AsyncWith") |
| 291 |
self.visit_sequence(node.items) |
| 292 |
self._validate_body(node.body, "AsyncWith") |
| 293 |
|
| 294 |
def visit_Raise(self, node): |
| 295 |
if node.exc: |
| 296 |
self._validate_expr(node.exc) |
| 297 |
if node.cause: |
| 298 |
self._validate_expr(node.cause) |
| 299 |
elif node.cause: |
| 300 |
raise ValidationError("Raise with cause but no exception") |
| 301 |
|
| 302 |
def visit_Try(self, node): |
| 303 |
self._validate_body(node.body, "Try") |
| 304 |
if not node.handlers and not node.finalbody: |
| 305 |
raise ValidationError( |
| 306 |
"Try has neither except handlers nor finalbody") |
| 307 |
if not node.handlers and node.orelse: |
| 308 |
raise ValidationError( |
| 309 |
"Try has orelse but no except handlers") |
| 310 |
for handler in node.handlers: |
| 311 |
handler.walkabout(self) |
| 312 |
self._validate_stmts(node.orelse) |
| 313 |
self._validate_stmts(node.finalbody) |
| 314 |
|
| 315 |
def visit_TryStar(self, node): |
| 316 |
self._validate_body(node.body, "TryStar") |
| 317 |
if not node.handlers and not node.finalbody: |
| 318 |
raise ValidationError( |
| 319 |
"TryStar has neither except handlers nor finalbody") |
| 320 |
if not node.handlers and node.orelse: |
| 321 |
raise ValidationError( |
| 322 |
"TryStar has orelse but no except handlers") |
| 323 |
for handler in node.handlers: |
| 324 |
handler.walkabout(self) |
| 325 |
self._validate_stmts(node.orelse) |
| 326 |
self._validate_stmts(node.finalbody) |
| 327 |
|
| 328 |
def visit_ExceptHandler(self, node): |
| 329 |
if node.type: |
| 330 |
self._validate_expr(node.type) |
| 331 |
self._validate_body(node.body, "ExceptHandler") |
| 332 |
|
| 333 |
def visit_Assert(self, node): |
| 334 |
self._validate_expr(node.test) |
| 335 |
if node.msg: |
| 336 |
self._validate_expr(node.msg) |
| 337 |
|
| 338 |
def visit_Import(self, node): |
| 339 |
self._validate_nonempty_seq(node.names, "names", "Import") |
| 340 |
|
| 341 |
def visit_ImportFrom(self, node): |
| 342 |
if node.level < 0: |
| 343 |
raise ValidationError("Negative ImportFrom level") |
| 344 |
self._validate_nonempty_seq(node.names, "names", "ImportFrom") |
| 345 |
|
| 346 |
def visit_Global(self, node): |
| 347 |
self._validate_nonempty_seq_s(node.names, "names", "Global") |
| 348 |
|
| 349 |
def visit_Nonlocal(self, node): |
| 350 |
self._validate_nonempty_seq_s(node.names, "names", "Nonlocal") |
| 351 |
|
| 352 |
def visit_Expr(self, node): |
| 353 |
self._validate_expr(node.value) |
| 354 |
|
| 355 |
def visit_Pass(self, node): |
| 356 |
pass |
| 357 |
|
| 358 |
def visit_Break(self, node): |
| 359 |
pass |
| 360 |
|
| 361 |
def visit_Continue(self, node): |
| 362 |
pass |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
def _validate_patterns(self, patterns, star_ok=False): |
| 367 |
if patterns: |
| 368 |
seen_star = False |
| 369 |
for pattern in patterns: |
| 370 |
if star_ok and isinstance(pattern, ast.MatchStar): |
| 371 |
if seen_star: |
| 372 |
raise ValidationError("multiple starred names in sequence pattern") |
| 373 |
self._validate_capture(pattern.name) |
| 374 |
seen_star = True |
| 375 |
continue |
| 376 |
pattern.walkabout(self) |
| 377 |
|
| 378 |
def _validate_capture(self, name): |
| 379 |
if name == "_": |
| 380 |
raise ValidationError("can't capture name '_' in patterns") |
| 381 |
self._validate_name(name) |
| 382 |
|
| 383 |
def visit_Match(self, node): |
| 384 |
self._validate_nonempty_seq(node.cases, "cases", "Match") |
| 385 |
self._validate_expr(node.subject) |
| 386 |
for case_ in node.cases: |
| 387 |
case_.walkabout(self) |
| 388 |
|
| 389 |
def visit_match_case(self, node): |
| 390 |
if node.guard: |
| 391 |
self._validate_expr(node.guard) |
| 392 |
self._validate_stmts(node.body) |
| 393 |
node.pattern.walkabout(self) |
| 394 |
|
| 395 |
def visit_MatchValue(self, node): |
| 396 |
space = self.space |
| 397 |
value = node.value |
| 398 |
self._validate_expr(value) |
| 399 |
if isinstance(value, ast.Constant): |
| 400 |
w_obj = value.value |
| 401 |
w_typ = space.type(w_obj) |
| 402 |
if (space.is_w(w_typ, space.w_int) or |
| 403 |
space.is_w(w_typ, space.w_float) or |
| 404 |
space.is_w(w_typ, space.w_unicode) or |
| 405 |
space.is_w(w_typ, space.w_bytes) or |
| 406 |
space.is_w(w_typ, space.w_complex)): |
| 407 |
return |
| 408 |
raise ValidationError("unexpected constant inside of a literal pattern") |
| 409 |
|
| 410 |
def visit_MatchSingleton(self, node): |
| 411 |
if (not self.space.is_w(node.value, self.space.w_True) and |
| 412 |
not self.space.is_w(node.value, self.space.w_False) and |
| 413 |
not self.space.is_w(node.value, self.space.w_None)): |
| 414 |
raise ValidationError( |
| 415 |
"MatchSingleton can only contain True, False and None") |
| 416 |
|
| 417 |
def visit_MatchSequence(self, node): |
| 418 |
self._validate_patterns(node.patterns, star_ok=True) |
| 419 |
|
| 420 |
def visit_MatchMapping(self, node): |
| 421 |
if node.keys and node.patterns and len(node.keys) != len(node.patterns): |
| 422 |
raise ValidationError("MatchMapping doesn't have the same number of keys as patterns") |
| 423 |
for key in node.keys: |
| 424 |
if isinstance(key, ast.Constant): |
| 425 |
continue |
| 426 |
if not isinstance(key, ast.Attribute): |
| 427 |
raise ValidationError("can only have Constant or Attribute in the keys of a MatchMapping") |
| 428 |
if node.rest is not None: |
| 429 |
self._validate_capture(node.rest) |
| 430 |
self._validate_patterns(node.keys) |
| 431 |
|
| 432 |
def visit_MatchClass(self, node): |
| 433 |
if len(node.kwd_attrs) != len(node.kwd_patterns): |
| 434 |
raise ValidationError("MatchClass doesn't have the same number of keyword attributes as patterns") |
| 435 |
self._validate_expr(node.cls) |
| 436 |
cls = node.cls |
| 437 |
while 1: |
| 438 |
if isinstance(cls, ast.Name): |
| 439 |
break |
| 440 |
if isinstance(cls, ast.Attribute): |
| 441 |
|
| 442 |
cls = cls.value |
| 443 |
else: |
| 444 |
raise ValidationError("MatchClass cls field can only contain Name or Attribute nodes.") |
| 445 |
for name in node.kwd_attrs: |
| 446 |
self._validate_name(name) |
| 447 |
self._validate_patterns(node.patterns) |
| 448 |
self._validate_patterns(node.kwd_patterns) |
| 449 |
|
| 450 |
def visit_MatchStar(self, node): |
| 451 |
raise ValidationError("can't use MatchStar here") |
| 452 |
|
| 453 |
def visit_MatchAs(self, node): |
| 454 |
if node.name: |
| 455 |
self._validate_capture(node.name) |
| 456 |
if node.pattern: |
| 457 |
if not node.name: |
| 458 |
raise ValidationError("MatchAs must specify a target name if a pattern is given") |
| 459 |
node.pattern.walkabout(self) |
| 460 |
|
| 461 |
def visit_MatchOr(self, node): |
| 462 |
if len(node.patterns) < 2: |
| 463 |
raise ValidationError("MatchOr requires at least 2 patterns") |
| 464 |
self._validate_patterns(node.patterns) |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
def visit_Name(self, node): |
| 469 |
self._validate_name(node.id) |
| 470 |
|
| 471 |
def visit_Constant(self, node): |
| 472 |
validate_constant(self.space, node.value) |
| 473 |
|
| 474 |
def visit_BoolOp(self, node): |
| 475 |
if self._len(node.values) < 2: |
| 476 |
raise ValidationError("BoolOp with less than 2 values") |
| 477 |
self._validate_exprs(node.values) |
| 478 |
|
| 479 |
def visit_UnaryOp(self, node): |
| 480 |
self._validate_expr(node.operand) |
| 481 |
|
| 482 |
def visit_BinOp(self, node): |
| 483 |
self._validate_expr(node.left) |
| 484 |
self._validate_expr(node.right) |
| 485 |
|
| 486 |
def visit_Lambda(self, node): |
| 487 |
node.args.walkabout(self) |
| 488 |
self._validate_expr(node.body) |
| 489 |
|
| 490 |
def visit_IfExp(self, node): |
| 491 |
self._validate_expr(node.test) |
| 492 |
self._validate_expr(node.body) |
| 493 |
self._validate_expr(node.orelse) |
| 494 |
|
| 495 |
def visit_Dict(self, node): |
| 496 |
if self._len(node.keys) != self._len(node.values): |
| 497 |
raise ValidationError( |
| 498 |
"Dict doesn't have the same number of keys as values") |
| 499 |
self._validate_exprs(node.keys, null_ok=True) |
| 500 |
self._validate_exprs(node.values) |
| 501 |
|
| 502 |
def visit_Set(self, node): |
| 503 |
self._validate_exprs(node.elts) |
| 504 |
|
| 505 |
def _validate_comprehension(self, generators): |
| 506 |
if not generators: |
| 507 |
raise ValidationError("comprehension with no generators") |
| 508 |
for comp in generators: |
| 509 |
assert isinstance(comp, ast.comprehension) |
| 510 |
self._validate_expr(comp.target, ast.Store) |
| 511 |
self._validate_expr(comp.iter) |
| 512 |
self._validate_exprs(comp.ifs) |
| 513 |
|
| 514 |
def visit_ListComp(self, node): |
| 515 |
self._validate_comprehension(node.generators) |
| 516 |
self._validate_expr(node.elt) |
| 517 |
|
| 518 |
def visit_SetComp(self, node): |
| 519 |
self._validate_comprehension(node.generators) |
| 520 |
self._validate_expr(node.elt) |
| 521 |
|
| 522 |
def visit_GeneratorExp(self, node): |
| 523 |
self._validate_comprehension(node.generators) |
| 524 |
self._validate_expr(node.elt) |
| 525 |
|
| 526 |
def visit_DictComp(self, node): |
| 527 |
self._validate_comprehension(node.generators) |
| 528 |
self._validate_expr(node.key) |
| 529 |
self._validate_expr(node.value) |
| 530 |
|
| 531 |
def visit_Yield(self, node): |
| 532 |
if node.value: |
| 533 |
self._validate_expr(node.value) |
| 534 |
|
| 535 |
def visit_YieldFrom(self, node): |
| 536 |
self._validate_expr(node.value) |
| 537 |
|
| 538 |
def visit_Compare(self, node): |
| 539 |
if not node.comparators: |
| 540 |
raise ValidationError("Compare with no comparators") |
| 541 |
if len(node.comparators) != len(node.ops): |
| 542 |
raise ValidationError("Compare has a different number " |
| 543 |
"of comparators and operands") |
| 544 |
self._validate_exprs(node.comparators) |
| 545 |
self._validate_expr(node.left) |
| 546 |
|
| 547 |
def visit_Call(self, node): |
| 548 |
self._validate_expr(node.func) |
| 549 |
self._validate_exprs(node.args) |
| 550 |
self.visit_sequence(node.keywords) |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
def visit_Attribute(self, node): |
| 557 |
self._validate_expr(node.value) |
| 558 |
|
| 559 |
def visit_Subscript(self, node): |
| 560 |
self._validate_expr(node.value) |
| 561 |
self._validate_expr(node.slice) |
| 562 |
|
| 563 |
def visit_RevDBMetaVar(self, node): |
| 564 |
pass |
| 565 |
|
| 566 |
|
| 567 |
def visit_Slice(self, node): |
| 568 |
if node.lower: |
| 569 |
self._validate_expr(node.lower) |
| 570 |
if node.upper: |
| 571 |
self._validate_expr(node.upper) |
| 572 |
if node.step: |
| 573 |
self._validate_expr(node.step) |
| 574 |
|
| 575 |
def visit_JoinedStr(self, node): |
| 576 |
self._validate_exprs(node.values) |
| 577 |
|
| 578 |
def visit_FormattedValue(self, node): |
| 579 |
self._validate_expr(node.value) |
| 580 |
if node.format_spec: |
| 581 |
self._validate_expr(node.format_spec) |
| 582 |
|
| 583 |
def visit_NamedExpr(self, node): |
| 584 |
if not isinstance(node.target, ast.Name): |
| 585 |
raise ValidationTypeError("NamedExpr target must be a Name") |
| 586 |
self._validate_expr(node.value) |
| 587 |
|
| 588 |
def visit_FunctionType(self, node): |
| 589 |
self._validate_exprs(node.argtypes) |
| 590 |
self._validate_expr(node.returns) |
| 591 |
|
| 592 |
def visit_Starred(self, node): |
| 593 |
self._validate_expr(node.value) |
| 594 |
|