Repository navigation
Adding stubs for ruamel.yaml
#12584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Adding stubs for ruamel.yaml
#12584
Changes from all commits
0437ed2
4933e44
4903841
cd19993
42448da
ca065c4
acc6f20
6a551f5
92cea96
a758f2c
e29899a
3ea806f
6110387
1f10574
bab20d8
b24c3c5
3c114d8
cbc6d83
a996c98
d0e3049
5cb0b5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| version = "0.19.*" | ||
| upstream-repository = "https://sourceforge.net/p/ruamel-yaml/code/" | ||
|
|
||
| [tool.stubtest] | ||
| skip = true # mypy parse errors in upstream package | ||
| stubtest-dependencies = ["configobj"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| from _typeshed import SupportsRead, SupportsWrite | ||
| from collections.abc import Mapping, Sequence | ||
|
|
||
| from ruamel.yaml.events import Event | ||
| from ruamel.yaml.nodes import Node | ||
| from ruamel.yaml.tokens import Token | ||
|
|
||
| def get_version_string() -> str: ... | ||
| def get_version() -> tuple[int, int, int]: ... | ||
|
|
||
| class Mark: | ||
| name: str | None | ||
| index: int | ||
| line: int | ||
| column: int | ||
| buffer: None | ||
| pointer: None | ||
| def __init__(self, name: str | None, index: int, line: int, column: int, buffer: None, pointer: None) -> None: ... | ||
| def get_snippet(self) -> None: ... | ||
|
|
||
| class CParser: | ||
| def __init__(self, stream: str | bytes | SupportsRead[str | bytes]) -> None: ... | ||
| def dispose(self) -> None: ... | ||
| def get_token(self) -> Token | None: ... | ||
| def peek_token(self) -> Token | None: ... | ||
| def check_token(self, *choices: type[Token]) -> bool: ... | ||
| def get_event(self) -> Event | None: ... | ||
| def peek_event(self) -> Event | None: ... | ||
| def check_event(self, *choices: type[Event]) -> bool: ... | ||
| def check_node(self) -> bool: ... | ||
| def get_node(self) -> Node | None: ... | ||
| def get_single_node(self) -> Node | None: ... | ||
| def raw_parse(self) -> int: ... | ||
| def raw_scan(self) -> int: ... | ||
|
|
||
| class CEmitter: | ||
| def __init__( | ||
| self, | ||
| stream: SupportsWrite[str | bytes], | ||
| canonical: bool | None = ..., | ||
| indent: int | None = ..., | ||
| width: int | None = ..., | ||
| allow_unicode: bool | None = ..., | ||
| line_break: str | None = ..., | ||
| encoding: str | None = ..., | ||
| explicit_start: bool | None = ..., | ||
| explicit_end: bool | None = ..., | ||
| version: Sequence[int] | None = ..., | ||
| tags: Mapping[str, str] | None = ..., | ||
| ) -> None: ... | ||
| def dispose(self) -> None: ... | ||
| def emit(self, event_object: Event) -> None: ... | ||
| def open(self) -> None: ... | ||
| def close(self) -> None: ... | ||
| def serialize(self, node: Node) -> None: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from typing import Final | ||
|
|
||
| from .comments import CommentedMap as CommentedMap, CommentedSeq as CommentedSeq | ||
| from .constructor import * | ||
| from .cyaml import * | ||
| from .dumper import * | ||
| from .error import YAMLError as YAMLError | ||
| from .events import * | ||
| from .loader import * | ||
| from .main import * | ||
| from .nodes import * | ||
| from .representer import * | ||
| from .resolver import * | ||
| from .tokens import * | ||
|
|
||
| version_info: Final[tuple[int, int, int]] | ||
| __version__: Final[str] | ||
| __with_libyaml__: Final[bool] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from typing import Final | ||
|
|
||
| anchor_attrib: Final = "_yaml_anchor" | ||
|
|
||
| class Anchor: | ||
| attrib: Final = anchor_attrib | ||
| value: str | None | ||
| always_dump: bool | ||
| def __init__(self) -> None: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| import sys | ||
| from _typeshed import SupportsWrite, sentinel | ||
| from collections.abc import Hashable, Iterable, Iterator, Mapping, MutableSet, Set as AbstractSet, Sized | ||
| from typing import Any, Final, Generic, NoReturn, TypeAlias, TypeVar | ||
| from typing_extensions import Self, deprecated | ||
|
|
||
| from .anchor import Anchor | ||
| from .compat import MutableSliceableSequence, ordereddict | ||
| from .mergevalue import MergeValue | ||
| from .nodes import _ScalarNodeStyle | ||
| from .tag import Tag | ||
| from .tokens import CommentToken, _CommentGroup | ||
|
|
||
| __all__ = [ | ||
| "CommentedSeq", | ||
| "CommentedKeySeq", | ||
| "CommentedMap", | ||
| "CommentedOrderedMap", | ||
| "CommentedSet", | ||
| "comment_attrib", | ||
| "merge_attrib", | ||
| "TaggedScalar", | ||
| "C_POST", | ||
| "C_PRE", | ||
| "C_SPLIT_ON_FIRST_BLANK", | ||
| "C_BLANK_LINE_PRESERVE_SPACE", | ||
| ] | ||
|
|
||
| _Index: TypeAlias = int | ||
| _Key: TypeAlias = Hashable | ||
|
|
||
| _T = TypeVar("_T") | ||
| _KT = TypeVar("_KT") | ||
| _VT = TypeVar("_VT") | ||
| _KT_co = TypeVar("_KT_co", covariant=True) | ||
| _VT_co = TypeVar("_VT_co", covariant=True) | ||
| _Commented = TypeVar("_Commented", bound=CommentedBase) | ||
|
|
||
| C_POST: Final = 0b00 | ||
| C_PRE: Final = 0b01 | ||
| C_SPLIT_ON_FIRST_BLANK: Final = 0b10 | ||
| C_BLANK_LINE_PRESERVE_SPACE: Final = 0b100 | ||
|
|
||
| comment_attrib: Final = "_yaml_comment" | ||
| format_attrib: Final = "_yaml_format" | ||
| line_col_attrib: Final = "_yaml_line_col" | ||
| merge_attrib: Final = "_yaml_merge" | ||
|
|
||
| class Comment: | ||
| attrib: Final = comment_attrib | ||
| comment: _CommentGroup | None | ||
| def __init__(self, *, old: bool = True) -> None: ... | ||
| @property | ||
| def items(self) -> dict[_Index | _Key, _CommentGroup]: ... | ||
|
|
||
| @property | ||
| @deprecated("RTSC functionality is experimental, unsupported, and known to fail") | ||
| def end(self): ... | ||
| @end.setter | ||
| @deprecated("RTSC functionality is experimental, unsupported, and known to fail") | ||
| def end(self, value) -> None: ... | ||
|
|
||
| @property | ||
| @deprecated("RTSC functionality is experimental, unsupported, and known to fail") | ||
| def pre(self): ... | ||
| @pre.setter | ||
| @deprecated("RTSC functionality is experimental, unsupported, and known to fail") | ||
| def pre(self, value) -> None: ... | ||
|
|
||
| @deprecated("RTSC functionality is experimental, unsupported, and known to fail") | ||
| def get(self, item: _Index | _Key, pos: int): ... | ||
| @deprecated("RTSC functionality is experimental, unsupported, and known to fail") | ||
| def set(self, item: _Index | _Key, pos: int, value: list[int]): ... | ||
| def __contains__(self, x: str, /) -> bool: ... | ||
|
|
||
| class Format: | ||
| attrib: Final = format_attrib | ||
| _flow_style: bool | None | ||
| def __init__(self) -> None: ... | ||
| def set_flow_style(self) -> None: ... | ||
| def set_block_style(self) -> None: ... | ||
| def flow_style(self, default: bool | None = None) -> bool | None: ... | ||
|
|
||
| class LineCol: | ||
| attrib: Final = line_col_attrib | ||
| line: int | None | ||
| col: int | None | ||
| data: dict[_Key, list[int]] | None | ||
| def __init__(self) -> None: ... | ||
| def add_kv_line_col(self, key: _Key, data: list[int]) -> None: ... | ||
| def key(self, k: _Key, /) -> tuple[int, int] | None: ... | ||
| def value(self, k: _Key, /) -> tuple[int, int] | None: ... | ||
| def item(self, idx: int, /) -> tuple[int, int] | None: ... | ||
| def add_idx_line_col(self, key: _Index, data: list[int]) -> None: ... | ||
|
|
||
| class CommentedBase: | ||
| @property | ||
| def ca(self) -> Comment: ... | ||
| def yaml_end_comment_extend(self, comment: list[CommentToken] | None, *, clear: bool = False) -> None: ... | ||
| def yaml_key_comment_extend(self, key: _Index | _Key, comment: _CommentGroup, *, clear: bool = False) -> None: ... | ||
| def yaml_value_comment_extend(self, key: _Key, comment: _CommentGroup, *, clear: bool = False) -> None: ... | ||
| def yaml_set_start_comment(self, comment: str, *, indent: int = 0) -> None: ... | ||
| def yaml_set_comment_before_after_key( | ||
| self, key: _Key, before: str | None = None, indent: int = 0, after: str | None = None, after_indent: int | None = None | ||
| ) -> None: ... | ||
| @property | ||
| def fa(self) -> Format: ... | ||
| def yaml_add_eol_comment(self, comment: str, key: _Index | _Key = sentinel, column: int | None = None) -> None: ... | ||
| @property | ||
| def lc(self) -> LineCol: ... | ||
| @property | ||
| def anchor(self) -> Anchor: ... | ||
| def yaml_anchor(self) -> Anchor | None: ... | ||
| def yaml_set_anchor(self, value: str, *, always_dump: bool = False) -> None: ... | ||
| @property | ||
| def tag(self) -> Tag: ... | ||
| def yaml_set_ctag(self, value: Tag, /) -> None: ... | ||
| def copy_attributes(self, t: _Commented, memo: dict[int, Any] | None = None) -> _Commented: ... | ||
|
|
||
| class CommentedSeq(MutableSliceableSequence[_T], list[_T], CommentedBase): # type: ignore[misc] # pyrefly: ignore [inconsistent-inheritance] | ||
| def __getsingleitem__(self, idx: int) -> _T: ... | ||
| def __setsingleitem__(self, idx: int, value: _T) -> None: ... | ||
| def __delsingleitem__(self, idx: int) -> None: ... | ||
| def __deepcopy__(self, memo: dict[int, Any]) -> Self: ... | ||
|
|
||
| class CommentedKeySeq(tuple[_T, ...], CommentedBase): ... | ||
|
|
||
| class CommentedMapView(Sized): | ||
| def __init__(self, mapping: CommentedMap[Any, Any]) -> None: ... | ||
| def __len__(self) -> int: ... | ||
|
|
||
| class CommentedMapKeysView(CommentedMapView, AbstractSet[_KT_co]): | ||
| def __init__(self, mapping: CommentedMap[_KT_co, Any]) -> None: ... | ||
| def __contains__(self, key: object) -> bool: ... | ||
| def __iter__(self) -> Iterator[_KT_co]: ... | ||
|
|
||
| class CommentedMapItemsView(CommentedMapView, AbstractSet[tuple[_KT_co, _VT_co]]): | ||
| def __init__(self, mapping: CommentedMap[_KT_co, _VT_co]) -> None: ... | ||
| def __contains__(self, item: object) -> bool: ... | ||
| def __iter__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ... | ||
|
|
||
| class CommentedMapValuesView(CommentedMapView, Generic[_VT_co]): | ||
| def __init__(self, mapping: CommentedMap[Any, _VT_co]) -> None: ... | ||
| def __contains__(self, value: object) -> bool: ... | ||
| def __iter__(self) -> Iterator[_VT_co]: ... | ||
|
|
||
| class CommentedMap(ordereddict[_KT, _VT], CommentedBase): | ||
| def insert(self, pos: int, key: _KT, value: _VT, comment: str | None = None) -> None: ... | ||
| def mlget(self, key: list[_Index | _Key], default: object = None, list_ok: bool = False) -> object: ... | ||
| def non_merged_items(self) -> Iterator[tuple[_KT, _VT]]: ... | ||
| def keys(self) -> CommentedMapKeysView[_KT]: ... # type: ignore[override] | ||
| def values(self) -> CommentedMapValuesView[_VT]: ... # type: ignore[override] | ||
| def items(self) -> CommentedMapItemsView[_KT, _VT]: ... # type: ignore[override] | ||
| @property | ||
| def merge(self) -> MergeValue | list[Self]: ... | ||
| def add_referent(self, cm: Self) -> None: ... | ||
| def add_yaml_merge(self, value: MergeValue) -> None: ... | ||
| def update_key_value(self, key: _KT) -> None: ... | ||
| def __deepcopy__(self, memo: dict[int, Any]) -> Self: ... | ||
|
|
||
| class CommentedKeyMap(CommentedBase, Mapping[_KT, _VT]): | ||
| def __init__(self, *args, **kwargs) -> None: ... | ||
| def __delitem__(self, *args, **kwargs) -> NoReturn: ... | ||
| def __setitem__(self, *args, **kwargs) -> NoReturn: ... | ||
| def clear(self, *args, **kwargs) -> NoReturn: ... | ||
| def pop(self, *args, **kwargs) -> NoReturn: ... | ||
| def popitem(self, *args, **kwargs) -> NoReturn: ... | ||
| def setdefault(self, *args, **kwargs) -> NoReturn: ... | ||
| def update(self, *args, **kwargs) -> NoReturn: ... | ||
| def __getitem__(self, index: _KT) -> _VT: ... | ||
| def __iter__(self) -> Iterator[_KT]: ... | ||
| def __len__(self) -> int: ... | ||
| def __hash__(self) -> int: ... | ||
| @classmethod | ||
| def fromkeys(keys, v=None) -> NoReturn: ... # broken | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently this crashes stubtest, as a workaround you may have to rename the param to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be fixed by python/mypy#21941 which I just merged (but it will take a while for it to get released). |
||
|
|
||
| class CommentedOrderedMap(CommentedMap[_KT, _VT]): ... | ||
|
|
||
| class CommentedSet(MutableSet[_T], CommentedBase): | ||
| odict: ordereddict[_T, None] | ||
| def __init__(self, values: Iterable[_T] | None = None) -> None: ... | ||
| def add(self, value: _T) -> None: ... | ||
| def discard(self, value: _T) -> None: ... | ||
| def __contains__(self, x: object) -> bool: ... | ||
| def __iter__(self) -> Iterator[_T]: ... | ||
| def __len__(self) -> int: ... | ||
|
|
||
| class TaggedScalar(CommentedBase): | ||
| value: str | None | ||
| style: _ScalarNodeStyle | None | ||
| def __init__(self, value: str | None = None, style: _ScalarNodeStyle | None = None, tag: Tag | str | None = None) -> None: ... | ||
| def count(self, s: str, start: int | None = None, end: int | None = None) -> int: ... | ||
| def __getitem__(self, pos: int | slice) -> str: ... | ||
|
|
||
| def dump_comments(d: object, name: str = "", sep: str = ".", out: SupportsWrite[str] = sys.stdout) -> None: ... | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| from _typeshed import SupportsRead, SupportsWrite | ||
| from abc import ABCMeta, abstractmethod | ||
| from collections import OrderedDict | ||
| from collections.abc import Iterable, MutableSequence | ||
| from typing import IO, Any, Final, TypeAlias, TypeVar, overload | ||
| from typing_extensions import Self | ||
|
|
||
| from .docinfo import Version | ||
|
|
||
| _T = TypeVar("_T") | ||
| _KT = TypeVar("_KT") | ||
| _VT = TypeVar("_VT") | ||
|
|
||
| _ReadStream: TypeAlias = str | bytes | SupportsRead[str] | SupportsRead[bytes] | ||
| _WriteStream: TypeAlias = SupportsWrite[str] | SupportsWrite[bytes] | ||
|
|
||
| StreamType: TypeAlias = _WriteStream | ||
| StreamTextType: TypeAlias = _ReadStream | ||
| VersionType: TypeAlias = str | tuple[int, int] | list[int] | Version | None | ||
|
|
||
| class ordereddict(OrderedDict[_KT, _VT]): | ||
| def insert(self, pos: int, key: _KT, value: _VT) -> None: ... | ||
|
|
||
| builtins_module: Final = "builtins" | ||
|
|
||
| def with_metaclass(meta, *bases): ... | ||
|
|
||
| DBG_TOKEN: Final = 1 | ||
| DBG_EVENT: Final = 2 | ||
| DBG_NODE: Final = 4 | ||
|
|
||
| def dbg(val: int | None = None) -> int: ... | ||
|
|
||
| class Nprint: | ||
| def __init__(self, file_name: str | None = None) -> None: ... | ||
| def __call__(self, *args, **kw) -> None: ... | ||
| def set_max_print(self, i: int) -> None: ... | ||
| def fp(self, mode: str = "a") -> IO[Any]: ... | ||
|
|
||
| nprint: Nprint | ||
| nprintf: Nprint | ||
|
|
||
| def check_namespace_char(ch: str) -> bool: ... | ||
| def check_anchorname_char(ch: str) -> bool: ... | ||
| def version_tnf(t1: tuple[int, ...], t2: tuple[int, ...] | None = None) -> bool | None: ... | ||
|
|
||
| class MutableSliceableSequence(MutableSequence[_T], metaclass=ABCMeta): | ||
| @overload | ||
| def __getitem__(self, index: int) -> _T: ... | ||
| @overload | ||
| def __getitem__(self, index: slice) -> Self: ... | ||
|
|
||
| @overload | ||
| def __setitem__(self, index: int, value: _T) -> None: ... | ||
| @overload | ||
| def __setitem__(self, index: slice, value: Iterable[_T]) -> None: ... | ||
|
|
||
| @overload | ||
| def __delitem__(self, index: int) -> None: ... | ||
| @overload | ||
| def __delitem__(self, index: slice) -> None: ... | ||
|
|
||
| @abstractmethod | ||
| def __getsingleitem__(self, index: int) -> _T: ... | ||
| @abstractmethod | ||
| def __setsingleitem__(self, index: int, value: _T) -> None: ... | ||
| @abstractmethod | ||
| def __delsingleitem__(self, index: int) -> None: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from .error import MarkedYAMLError | ||
| from .events import MappingEndEvent, SequenceEndEvent | ||
| from .loader import _Loader | ||
| from .main import YAML | ||
| from .nodes import CollectionNode, MappingNode, Node, ScalarNode, SequenceNode | ||
| from .parser import Parser | ||
| from .resolver import BaseResolver | ||
|
|
||
| __all__ = ["Composer", "ComposerError", "MaxDepthExceededError"] | ||
|
|
||
| class ComposerError(MarkedYAMLError): ... | ||
| class MaxDepthExceededError(MarkedYAMLError): ... | ||
|
|
||
| class Composer: | ||
| loader: YAML | _Loader | None | ||
| anchors: dict[str, Node] | ||
| warn_double_anchors: bool | ||
| depth: int | ||
| def __init__(self, loader: YAML | _Loader | None = None) -> None: ... | ||
| @property | ||
| def parser(self) -> Parser: ... | ||
| @property | ||
| def resolver(self) -> BaseResolver: ... | ||
| def check_node(self) -> bool: ... | ||
| def get_node(self) -> Node: ... | ||
| def get_single_node(self) -> Node: ... | ||
| def compose_document(self) -> Node: ... | ||
| def return_alias(self, a: Node) -> Node: ... | ||
| def compose_node(self, parent: CollectionNode | None, index: int | Node | None) -> Node: ... | ||
| def compose_scalar_node(self, anchor: str | None) -> ScalarNode: ... | ||
| def compose_sequence_node(self, anchor: str | None) -> SequenceNode: ... | ||
| def compose_mapping_node(self, anchor: str | None) -> MappingNode: ... | ||
| def check_end_doc_comment(self, end_event: SequenceEndEvent | MappingEndEvent, node: SequenceNode | MappingNode) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer seems to be the case, can you try re-enabling stubtest?