02 - Direct access to fields¶
Status: Accepted
Date: 2026-02-25
Authors:
- jinmin.hu@capgemini.com
- huub.joosten@capgemini.com
- luna.li@capgemini.com
- paul.nelissen@esi.nl
- pierre.vandelaar@tno.nl
Table of contents¶
- Context
- Decision
- Implementation notes
- Rationale
- Consequences
- Alternatives considered
- Related decisions
Context¶
The goal of this ADR is to allow the developer of a new language for Renaissance to create refactorings that is expressive and concise
Direct access refers to exposing node fields and attributes using a Pythonic style (e.g., function_definition.body, function_definition.name)
rather than using children and properties such as function_definition.children[3].children or function_definition.properties['name'].
This allows for natural attribute access, simpler metaprogramming, and compatibility with Python tooling and idioms.
Decision¶
Adopt a Pythonic direct-access convention for node definitions. Nodes may declare a _fields(as in CPython's ast
module) that names structural fields. Consumers and tools should read these fields rather than
relying on children and properties methods. Implementations should still provide stable,
documented APIs for direct ast node manipulation.
Implementation notes¶
ASTExtension in src/renaissance/integrations/python/ast/ast_node.py derives the matcher's properties and
children from the _fields of CPython's ast nodes:
class ASTExtension:
@staticmethod
@property
def ast_properties(self) -> dict[str, Any]:
return {field: getattr(self, field) for field in self._fields if not isinstance(getattr(self, field), ast.AST)}
@staticmethod
@property
def ast_children(self) -> list[ast.AST]:
children = [getattr(self, field) for field in self._fields if isinstance(getattr(self, field), ast.AST)]
[children.extend(getattr(self, field)) for field in self._fields if isinstance(getattr(self, field), list)]
return children
Rationale¶
Using Python conventions reduces boilerplate, makes code easier to inspect and manipulate, and aligns with developer expectations in a Python project.
Consequences¶
Positive:
- Lower boilerplate and clearer node definitions.
- Easier integration with Python tooling.
Negative:
- Slight coupling to Python conventions; if we port the model to other languages some idioms will differ.
Alternatives considered¶
- Exclusive use of accessor methods — rejected because it increases verbosity and reduces interop with Python tooling.
Related decisions¶
- See ADR 01 (Children and properties) and ADR 04 (Make nodes immutable).
Revision history:
- 2026-02-25: Converted to ADR template and clarified decision.
- 2026-11-02: Replaced the example with
ASTExtension.