Module

analysis.shape_profiles

Deterministic, policy-neutral template shape profiles.

This module measures source structure without rendering and without turning the facts into advice. The parser subclass records block-end positions only for an explicit profiling call; ordinary parsing and compilation are unchanged.

Classes

ShapeFacts 15
Independent measurements for one template-owned source region.

Independent measurements for one template-owned source region.

Attributes

Name Type Description
node_count int
source_lines int
max_depth int
branch_count int
loop_count int
dynamic_expression_count int
dynamic_density_basis_points int
component_call_count int
slot_count int
literal_attribute_count int
repeated_shape_groups int
context_dependencies tuple[str, ...]
structural_fingerprint str

Methods

to_dict 0 dict[str, object]
Return a JSON-compatible mapping with deterministic field values.
def to_dict(self) -> dict[str, object]
Returns
dict[str, object]
Internal Methods 1
__post_init__ 0
def __post_init__(self) -> None
ShapeProfile 6
Shape facts and exact ownership span for one analyzed region.

Shape facts and exact ownership span for one analyzed region.

Attributes

Name Type Description
kind ShapeProfileKind
name str | None
span SourceSpan
facts ShapeFacts

Methods

to_dict 0 dict[str, object]
Return this profile as a deterministic JSON-compatible mapping.
def to_dict(self) -> dict[str, object]
Returns
dict[str, object]
Internal Methods 1
__post_init__ 0
def __post_init__(self) -> None
ShapeProfileReport 5
Policy-neutral result of one shape-profile request.

Policy-neutral result of one shape-profile request.

Attributes

Name Type Description
template_name str
profiles tuple[ShapeProfile, ...]
partial bool

Methods

to_dict 0 dict[str, object]
Return the stable shape-profile v1 structured representation.
def to_dict(self) -> dict[str, object]
Returns
dict[str, object]
Internal Methods 1
__post_init__ 0
def __post_init__(self) -> None

Functions

profile_source 3 ShapeProfileReport
Profile in-memory template source without rendering or caching it.
def profile_source(source: str, *, name: str = '<string>', environment: Environment | None = None) -> ShapeProfileReport
Parameters
Name Type Description
source str
name str Default:'<string>'
environment Environment | None Default:None
Returns
ShapeProfileReport
profile_template 1 ShapeProfileReport
Profile a compiled template from its retained source. Re-parsing is intentiona…
def profile_template(template: CompiledTemplate) -> ShapeProfileReport

Profile a compiled template from its retained source.

Re-parsing is intentional: the result describes source shape rather than optimization artifacts, so fresh compilations and bytecode-cache hits have identical profiles. A partial empty report is returned only when the compiled template no longer has retained source or its environment.

Parameters
Name Type Description
template CompiledTemplate
Returns
ShapeProfileReport