Block: Parsed Code Block#
- class arch.code.Block.Block(*, sig='', doc=<factory>, code=<factory>, lang=Lang.PY, indent=0, annotations=<factory>, name='', args=<factory>, type='')#
A parsed block of source code: a signature plus its docstring and body.
Parsing is regex-driven (see RGXS) and language-aware, currently covering Python and TypeScript. Subclasses refine the model for whole classes (Module) and files (File).
- class Arg(*, key='', ann='', val='')#
A single parsed argument: its name, annotation, and default value.
- classmethod new(text)#
Parse a single argument string into an Arg, returning an empty Arg on failure.
- property base#
The base form of this argument’s annotation.
- all_bases()#
Return every base type named in this argument’s annotation, split on unions.
- static ann_base(ann)#
Reduce an annotation to its base form, e.g. “dict” instead of “dict[str, str]”.
- model_config = {}#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- classmethod new(**kwargs)#
Build a block, splitting raw
argsandannotationsstrings into lists first.
- serialize()#
Serialize this block to its rendered string form.
- property type_base#
The ‘base’ type returned by this block, if any.
Base types are the underlying, non-parameterized versions of the original types, e.g. “dict” instead of “dict[str, str]”.
- render()#
Render the signature and code of this block into a tuple of strings.
Written with the intention that subclasses will override it.
- Returns:
The “signature” of this block (if any), such as a class or function declaration line.
The “code” of this block, which is all its content other than the signature.
- parse_methods()#
Parse the methods defined in this block’s code.
- Returns:
A mapping of section name to method blocks – just ‘code’ for a plain block – or an empty dict when no methods are found.
- typeset()#
Collect a set of all the non-implicit types referenced by this block’s signature.
Both the arguments and the return value are covered, if either are present in the first place.
- Returns:
A set of strings naming type “bases”, e.g. “dict” rather than “dict[str, str]”.
- property is_static#
Return True if the method is static, False otherwise.
- property is_property#
Return True if the method is a property, False otherwise.
- model_config = {}#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].