diff options
author | Benjamin Schubert <contact@benschubert.me> | 2020-08-29 12:02:16 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-08-30 15:36:34 +0000 |
commit | 80b8dc528e38c7e12f8dcbaed79ac6311e612cf2 (patch) | |
tree | 64d806cd21d9d83a43aa1f2984fe3ac501050348 | |
parent | 20efef5ee45ca8acee893a4a7e89a96f1c773fc5 (diff) | |
download | buildstream-80b8dc528e38c7e12f8dcbaed79ac6311e612cf2.tar.gz |
node.pyi: Add type annotations for the node module
This does not contain all the possible needed annotations, but just
enough to have mypy pass.
-rw-r--r-- | setup.cfg | 5 | ||||
-rw-r--r-- | src/buildstream/element.py | 4 | ||||
-rw-r--r-- | src/buildstream/node.pyi | 29 |
3 files changed, 31 insertions, 7 deletions
@@ -31,11 +31,6 @@ warn_no_return = True [mypy-copyreg,grpc,pluginbase,psutil,py,pyroaring,pytest,_pytest.*,ruamel] ignore_missing_imports=True -# Ignore missing stubs for Cythonized modules. -# In future, these should be re-enabled by writing stubs for them. -[mypy-buildstream.node] -ignore_missing_imports=True - # Ignore issues with generated files and vendored code [mypy-buildstream._protos.*,buildstream._version] ignore_errors = True diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 4a29fd8f2..4995f1f37 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -780,7 +780,7 @@ class Element(Plugin): """ self._stage_sources_in_sandbox(sandbox, directory) - def get_public_data(self, domain: str) -> "MappingNode[Any, Any]": + def get_public_data(self, domain: str) -> "MappingNode[Node]": """Fetch public data on this element Args: @@ -805,7 +805,7 @@ class Element(Plugin): return data - def set_public_data(self, domain: str, data: "MappingNode[Any, Any]") -> None: + def set_public_data(self, domain: str, data: "MappingNode[Node]") -> None: """Set public data on this element Args: diff --git a/src/buildstream/node.pyi b/src/buildstream/node.pyi new file mode 100644 index 000000000..57083602c --- /dev/null +++ b/src/buildstream/node.pyi @@ -0,0 +1,29 @@ +from typing import Generic, List, Mapping, Optional, Sequence, TypeVar + +from ._project import Project + +TNode = TypeVar("TNode", bound="Node") +TValidNodeValue = TypeVar("TValidNodeValue", int, str, bool, Mapping, Sequence) + +class ProvenanceInformation: ... + +class Node: + def clone(self) -> "Node": ... + +class MappingNode(Node, Generic[TNode]): + def __init__(self, file_index: int, line: int, column: int, value: Mapping[str, TValidNodeValue]) -> None: ... + def clone(self) -> MappingNode[TNode]: ... + def get_str_list(self, key: str, default: List[str] = None) -> List[str]: ... + +class ScalarNode(Node): + def as_str(self) -> str: ... + def clone(self) -> "ScalarNode": ... + +class SequenceNode(Node, Generic[TNode]): + def as_str_list(self) -> List[str]: ... + def clone(self) -> "SequenceNode[TNode]": ... + +def _assert_symbol_name( + symbol_name: str, purpose: str, *, ref_node: Optional[Node] = None, allow_dashes: bool = True +) -> None: ... +def _new_synthetic_file(filename: str, project: Optional[Project] = None) -> MappingNode[TNode]: ... |