summaryrefslogtreecommitdiff
path: root/src/buildstream/node.pyi
blob: 23db809767c3716754cc6d87a6548a0687b182b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from enum import Enum
from typing import Optional, TypeVar, Generic, Union, Dict, Type, Mapping, List, ItemsView, KeysView, ValuesView, Iterator, Any

from buildstream._project import Project


TAllowedScalars = Union[None, bool, int, str]
TAllowedNodeValues = Union[TAllowedScalars, List, Dict[str, Any]]
TSelf = TypeVar("TSelf")

TNode = TypeVar("TNode", bound='Node')
T = TypeVar("T", bound=TAllowedNodeValues)
TEnum = TypeVar("TEnum", bound=Enum)


class Node(Generic[T]):
    def clone(self: TSelf) -> TSelf: ...
    def from_dict(self, value: Dict[str, TAllowedScalars]) -> MappingNode: ...
    def get_provenance(self) -> ProvenanceInformation: ...
    def strip_node_info(self) -> T: ...


class MappingNode(Node[Dict[str, TNode]]):
    def __init__(self, file_index: int, line: int, column: int, value: Dict[str, Node]) -> None: ...
    def __contains__(self, item: Node) -> bool: ...
    def __delitem__(self, key: str) -> None: ...
    def __setitem__(self, key: str, value: Union[Node, TAllowedNodeValues]) -> None: ...
    def get_bool(self, key: str, default: Optional[bool]) -> bool: ...
    def get_enum(self, key: str, constraint: Type[TEnum], default: Optional[TEnum]) -> TEnum: ...
    def get_int(self, key: str, default: Optional[int]) -> int: ...
    def get_mapping(self, key: str, default: Optional[Dict[str, TAllowedNodeValues]]) -> MappingNode: ...
    def get_node(self, key: str, allowed_types: Optional[List[Type[Node]]], allow_none: bool) -> Node: ...
    def get_scalar(self, key: str, default: Optional[TAllowedScalars]) -> None: ...
    def get_sequence(self, key: str, default: Optional[List[TAllowedNodeValues]]) -> SequenceNode: ...
    def get_str(self, key: str, default=Optional[str]) -> str: ...
    def get_str_list(self, key: str, default=Optional[List[str]]) -> List[str]: ...
    def items(self) -> ItemsView[str, Node]: ...
    def keys(self) -> KeysView[str]: ...
    def safe_del(self, key: str) -> None: ...
    def validate_keys(self, valid_keys: List[str]) -> None: ...
    def values(self) -> ValuesView[Node]: ...


class ScalarNode(Node[str]):
    def __init__(self, file_index: int, line: int, column: int, value: TAllowedScalars) -> None: ...
    def as_bool(self) -> bool: ...
    def as_enum(self, constraint: Type[TEnum]) -> TEnum: ...
    def as_int(self) -> int: ...
    def as_str(self) -> str: ...
    def is_none(self) -> bool: ...


class SequenceNode(Node[List[TNode]]):
    def __init__(self, file_index: int, line: int, column: int, value: List[TNode]) -> None: ...
    def __iter__(self) -> Iterator[TNode]: ...
    def __len__(self) -> int: ...
    def __reversed__(self) -> Iterator[int]: ...
    def __setitem__(self, key: str, value: Union[TNode, TAllowedNodeValues]) -> None: ...
    def append(self, value: Union[TNode, TAllowedNodeValues]) -> None: ...
    def as_str_list(self) -> List[str]: ...
    def mapping_at(self, index: int) -> MappingNode: ...
    def node_at(self, index: int, allowed_types: Optional[List[Type[TNode]]]) -> Node: ...
    def scalar_at(self, index: int) -> ScalarNode: ...
    def sequence_at(self, index: int) -> SequenceNode: ...


class ProvenanceInformation: ...


def _assert_symbol_name(symbol_name: str, purpose: str, *, ref_node=Optional[Node], allow_dashes: bool) -> None: ...
def _new_synthetic_file(filename: str, project: Project): ...