Codegen uses a set of core behaviors that can be inherited by code elements. These behaviors provide consistent APIs across different types of symbols.
The HasName behavior provides APIs for working with named elements:
Copy
Ask AI
# Access the nameprint(function.name) # Base name without namespaceprint(function.full_name) # Full qualified name with namespace# Modify the namefunction.set_name("new_name") # Changes just the namefunction.rename("new_name") # Changes name and updates all usages# Get the underlying name nodename_node = function.get_name()
The HasValue behavior provides APIs for elements that have values:
Copy
Ask AI
# Access the valuevalue = variable.value # Gets the value Expression nodeprint(value.source) # Gets the string content# Modify the valuevariable.set_value("new_value")# Common patternsif variable.value is not None: print(f"{variable.name} = {variable.value.source}")