simvx.core.scene_io.source._source_ast.names

What an ast statement binds and what it merely names.

The two questions the tier above asks of every statement: which names it establishes (so a removal knows what it carries off) and which names it writes at all (so a removal knows what would be left standing on nothing, and a rename knows what to rewrite). Attributes are spelled self.<name> in both answers, which is how the tier above tells the two kinds apart.

Where ast is better than a concrete tree here, it is used: a name bound by a match capture pattern is a binding this file reports and no grammar table had to be taught. Where ast is worse, it is worse in one direction only: the names it stores as plain strings rather than as nodes – an except ... as e, an import’s module path, a global declaration, a parameter – are bindings this file still reports but mentions it does not, so a rename leaves them alone. That is the safe direction: a rename that stops short is visible, and one that reaches into a parameter of a nested function would be wrong.

Module Contents

Functions

bound_names

Every name node binds, attributes spelled self.<name>.

mentioned_names

Every name node writes, bound there or not, self.<name> for attributes.

local_name_nodes

Every occurrence of the local name under node, in source order.

imported_names

What an import imports, as (name as written, alias or None) pairs.

import_module_path

The module a from import names, dots and all, or None for a plain import.

Data

API

simvx.core.scene_io.source._source_ast.names.__all__

[‘bound_names’, ‘import_module_path’, ‘imported_names’, ‘local_name_nodes’, ‘mentioned_names’]

simvx.core.scene_io.source._source_ast.names.bound_names(node: ast.AST) set[str][source]

Every name node binds, attributes spelled self.<name>.

A statement carrying a block is asked about its whole block, since a name bound inside one is bound by the statement as far as anything outside it can tell. The two bodies that bind only for themselves are the exception: a lambda is not descended into at all, and a nested def or class contributes only the name it is given.

simvx.core.scene_io.source._source_ast.names.mentioned_names(node: ast.AST) set[str][source]

Every name node writes, bound there or not, self.<name> for attributes.

simvx.core.scene_io.source._source_ast.names.local_name_nodes(node: ast.AST, name: str) list[ast.Name][source]

Every occurrence of the local name under node, in source order.

The rename surface: each of these spells a variable and nothing else, so replacing its span is a rename. The self of self.hero is not one of them, because that occurrence names an attribute rather than a local.

simvx.core.scene_io.source._source_ast.names.imported_names(node: ast.stmt) list[tuple[str, str | None]][source]

What an import imports, as (name as written, alias or None) pairs.

from a import * imports nothing this can name and comes back empty.

simvx.core.scene_io.source._source_ast.names.import_module_path(node: ast.stmt) str | None[source]

The module a from import names, dots and all, or None for a plain import.