Skip to content

Scan fields

ScanFields

ScanFields(cls: type, **kwargs: Unpack[StatementOptions])

Bases: BaseModifier

Source code in src/kirin/decl/base.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(self, cls: type, **kwargs: Unpack[StatementOptions]) -> None:
    self.cls = cls
    self.cls_module = sys.modules.get(cls.__module__)

    if "dialect" in kwargs:
        self.dialect = kwargs["dialect"]
    else:
        self.dialect = None
    self.params = kwargs
    setattr(cls, self._PARAMS, self.params)

    if cls.__module__ in sys.modules:
        self.globals = sys.modules[cls.__module__].__dict__
    else:
        # Theoretically this can happen if someone writes
        # a custom string to cls.__module__.  In which case
        # such dataclass won't be fully introspectable
        # (w.r.t. typing.get_type_hints) but will still function
        # correctly.
        self.globals: dict[str, Any] = {}

    # analysis state, used by scan_field, etc.
    self.fields = StatementFields()
    self.has_statement_bases = False
    self.kw_only = self.params.get("kw_only", False)
    self.KW_ONLY_seen = False