-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Adding stubs for ruamel.yaml
#12584
Open
stevenlele
wants to merge
16
commits into
python:main
Choose a base branch
from
stevenlele:ruamel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Adding stubs for ruamel.yaml
#12584
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0437ed2
Auto generate
stevenlele 4933e44
Regenerate with Any removed
stevenlele 4903841
Fix some import errors
stevenlele cd19993
Some initial typing effort
stevenlele 42448da
Finish all except main (thanks, MonkeyType)
stevenlele ca065c4
Small fixes
stevenlele acc6f20
configobj is an optional dependency
stevenlele 6a551f5
Finish main plus style fixes and PyYAML stubs parity
stevenlele 92cea96
Fix or ignore mypy errors
stevenlele a758f2c
Fix some errors reported by mypy_primer
stevenlele e29899a
Attempt to fix pytype errors
stevenlele 3ea806f
Remove debug variables to make pytype happy
stevenlele 6110387
Merge branch 'main' into ruamel
stevenlele 1f10574
Minor fixes
stevenlele bab20d8
Disable stubtest
stevenlele b24c3c5
Remove unused type ignore comments
stevenlele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version = "0.18.*" | ||
upstream_repository = "https://sourceforge.net/p/ruamel-yaml/code/" | ||
|
||
[tool.stubtest] | ||
skip = true # mypy parse errors in upstream package | ||
stubtest_requirements = ["configobj"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[Token]) -> 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: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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: tuple[int, int, int] | ||
__version__: str | ||
__with_libyaml__: bool | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
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, TypeVar | ||
from typing_extensions import Self, TypeAlias | ||
|
||
from .anchor import Anchor | ||
from .compat import MutableSliceableSequence, ordereddict | ||
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 | ||
def end(self): ... # RTSC | ||
@end.setter | ||
def end(self, value) -> None: ... # RTSC | ||
@property | ||
def pre(self): ... # RTSC | ||
@pre.setter | ||
def pre(self, value) -> None: ... # RTSC | ||
def get(self, item: _Index | _Key, pos: int): ... # RTSC | ||
def set(self, item: _Index | _Key, pos: int, value: list[int]): ... # RTSC | ||
def __contains__(self, x: str, /) -> bool: ... | ||
|
||
class Format: | ||
attrib: Final = format_attrib | ||
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: str, /) -> tuple[int, int] | None: ... | ||
def value(self, k: str, /) -> 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] | ||
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: Any = None, list_ok: bool = False) -> Any: ... | ||
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) -> list[tuple[int, Self]]: ... | ||
def add_referent(self, cm: Self) -> None: ... | ||
def add_yaml_merge(self, value: list[tuple[int, Self]]) -> 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 | ||
|
||
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) -> str: ... | ||
|
||
def dump_comments(d: object, name: str = "", sep: str = ".", out: SupportsWrite[str] = sys.stdout) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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, TypeVar, overload | ||
from typing_extensions import Self, TypeAlias | ||
|
||
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: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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"] | ||
|
||
class ComposerError(MarkedYAMLError): ... | ||
|
||
class Composer: | ||
loader: YAML | _Loader | None | ||
anchors: dict[str, Node] | ||
warn_double_anchors: bool | ||
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: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from collections.abc import Iterator | ||
from typing_extensions import deprecated | ||
|
||
from configobj import ConfigObj # type: ignore[import-not-found] # pyright: ignore[reportMissingImports] | ||
|
||
@deprecated("configobj_walker has moved to ruamel.yaml.util") | ||
def configobj_walker(cfg: ConfigObj, /) -> Iterator[str]: ... |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The should most likely be final:
(Needs import from
typing
.)