(node_id: str, context: EvaluationContext)
| 1443 | |
| 1444 | |
| 1445 | def _eval_node_name(node_id: str, context: EvaluationContext): |
| 1446 | policy = get_policy(context) |
| 1447 | if node_id in context.transient_locals: |
| 1448 | return context.transient_locals[node_id] |
| 1449 | if policy.allow_locals_access and node_id in context.locals: |
| 1450 | return context.locals[node_id] |
| 1451 | if policy.allow_globals_access and node_id in context.globals: |
| 1452 | return context.globals[node_id] |
| 1453 | if policy.allow_builtins_access and hasattr(builtins, node_id): |
| 1454 | # note: do not use __builtins__, it is implementation detail of cPython |
| 1455 | return getattr(builtins, node_id) |
| 1456 | if policy.allow_auto_import and context.auto_import: |
| 1457 | return context.auto_import(node_id) |
| 1458 | if not policy.allow_globals_access and not policy.allow_locals_access: |
| 1459 | raise GuardRejection( |
| 1460 | f"Namespace access not allowed in {context.evaluation} mode" |
| 1461 | ) |
| 1462 | else: |
| 1463 | raise NameError(f"{node_id} not found in locals, globals, nor builtins") |
| 1464 | |
| 1465 | |
| 1466 | def _eval_or_create_duck(duck_type, context: EvaluationContext): |
no test coverage detected
searching dependent graphs…