Skip to content

quast_decisiontree.core.path

quast_decisiontree.core.path

PathKey dataclass

Declares a path_info key a node may read: its type and allowed values.

options is None means any value of dtype is accepted. Subclasses may add fields and override is_valid for finer checks.

Source code in src/quast_decisiontree/core/path.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@dataclass(frozen=True)
class PathKey:
    """Declares a path_info key a node may read: its type and allowed values.

    `options is None` means any value of `dtype` is accepted. Subclasses may
    add fields and override `is_valid` for finer checks.
    """

    dtype: type
    options: list | None = None

    def is_valid(self, value: object) -> bool:
        if not isinstance(value, self.dtype):
            return False
        return self.options is None or value in self.options

    def to_dict(self) -> dict:
        return dict(
            dtype=self.dtype.__name__,
            options=self.options,
        )

dtype instance-attribute

dtype

options class-attribute instance-attribute

options = None

__init__

__init__(dtype, options=None)

is_valid

is_valid(value)
Source code in src/quast_decisiontree/core/path.py
23
24
25
26
def is_valid(self, value: object) -> bool:
    if not isinstance(value, self.dtype):
        return False
    return self.options is None or value in self.options

to_dict

to_dict()
Source code in src/quast_decisiontree/core/path.py
28
29
30
31
32
def to_dict(self) -> dict:
    return dict(
        dtype=self.dtype.__name__,
        options=self.options,
    )