symbol_short_name
def symbol_short_name(
symbol
):Return the final dotted component of a symbol name.
Write tools accept plain text because that is what agents and humans can produce quickly. This section turns that text into real cells: split on block separators, honor %%markdown/%%code markers, and split exported code into symbol-sized chunks when needed. It is the small parser that makes notebook edits feel like editing a document instead of assembling JSON.
symbol_short_name derives a display alias from a qualified name. Keep the qualified name in records because different modules can expose the same short name.
symbol_short_name removes the owner prefix when a caller needs only the local symbol name.
Return the final dotted component of a symbol name.
Graph records retain dotted names through call_name. symbol_short_name and short_call_name derive display aliases from those names; a call target that cannot be named remains None or the supplied default.
call_name preserves qualification when resolving a call target.
Return dotted name text for an AST name, attribute, or call expression.
Return dotted call names and source locations from one parsed Python tree.
call_sites gives calls one representation in foundation. Graph navigation can add short aliases while retaining the original source locations.
short_call_name selects the local component of an AST call target.
Return the final dotted component of a call/name node, or default.
is_definition_node recognizes classes as well as synchronous and asynchronous functions. Definition consumers share this predicate instead of maintaining different AST type lists.
is_definition_node distinguishes declarations from ordinary statements.
Return whether an AST node defines a function or class.
node_start_line includes decorators when selecting a definition for editing.
Return the zero-based start line including decorators.
The shared directive reader uses fastcore to merge comment and metadata directives. This keeps export detection and execution consistent with nbdev 3.3, including colon variants and comment precedence.
Return normalized nbdev directives, with comments taking precedence over metadata.
cell_directives merges metadata and leading comments through fastcore. Using one parser prevents export detection from disagreeing with execution about the same cell.
Return whether a line directs executable code to a module.
is_export_directive recognizes executable export directives through the shared parser, including their colon spellings.
Python notebook blocks can contain exported and non-exported regions. The splitter retains source order and separates those regions before creating cells.
Multiple definitions in an exported cell become separate cells. Their order and export directives remain intact.
parse_cells normalizes text blocks or existing cell structures before splitting exported definitions into separate cells.
Normalize cell structures or marked text blocks into notebook cells.
parse_one_cell enforces the single-cell boundary used by replacement operations. Multiple blocks need a structural edit instead.
Normalize one cell block and reject multi-cell replacements.
mixed_cells = _split_symbol_cells([mk_cell("#| export\ndef first(): return 1\n\ndef second(): return 2")])
assert len(mixed_cells) == 2
assert "def first" in mixed_cells[0].source and "def second" in mixed_cells[1].source
assert all(cell.source.startswith("#| export") for cell in mixed_cells)
[cell.source for cell in mixed_cells]The notebook format permits source as one string or a list of fragments. cell_source normalizes both at the read boundary; the cell object remains the source of metadata and outputs.
Return cell source as one string for mapping and object inputs.
parse_cell retains the syntax error alongside the AST result. Source analysis needs that distinction to report malformed Python without dropping the original cell.
Return a Python AST and syntax error separately without changing the cell.
parse_code_cell returns a tree for valid code and None for malformed or non-code cells. Use cell_analysis when the reason for a failed parse matters.
Return the Python tree, or None for non-code and unparseable source.
parse_code_cell keeps its tree-or-None interface for AST consumers. Use cell_analysis when a caller must distinguish a parse failure from non-code and inspect the original exception.