Skip to content
Sarj Code Standards

no-dynamic-builtins

Use explicit typed state instead of dynamic Python builtin access.

Why

Dynamic namespace inspection, source compilation, and string-based attribute access hide dependencies from type checking and refactoring. The strict policy also rejects executor/debugger references that can otherwise escape their native call checks through an alias.

Fix

Pass typed state explicitly, use explicit imports and declared attributes, and keep source as data. A required compiler or plugin boundary needs a local, explained suppression.

Examples

Before — flagged A string field name hides the object contract
service/reader.py
def read(value, field):
return getattr(value, field, None)
After — preferred A declared field makes the contract explicit
service/reader.py
from dataclasses import dataclass
@dataclass(frozen=True)
class User:
name: str
def read(value: User) -> str:
return value.name