Skip to content

Add basic type annotations for YAML load functions #1657

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

Merged
merged 1 commit into from
Oct 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions third_party/2and3/yaml/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Iterator, Union, IO
from yaml.error import * # noqa: F403
from yaml.tokens import * # noqa: F403
from yaml.events import * # noqa: F403
Expand All @@ -14,10 +14,10 @@ def scan(stream, Loader=...): ...
def parse(stream, Loader=...): ...
def compose(stream, Loader=...): ...
def compose_all(stream, Loader=...): ...
def load(stream, Loader=...): ...
def load_all(stream, Loader=...): ...
def safe_load(stream): ...
def safe_load_all(stream): ...
def load(stream: Union[str, IO[str]], Loader: Loader=...) -> Any: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered a problem with the annotation for Loader here. IIUC it's intended that this argument can be an instance of BaseLoader or SafeLoader as well. But given the inheritance structure in loader.pyi that doesn't work -- if I pass an instance of SafeLoader I get a type error. Maybe you can fix this by declaring this argument (here and below) as Union[BaseLoader, SafeLoader, Loader]? (Do double check that I got this right -- I'm not a user of yaml myself, but I found this caused a regression in an internal Dropbox codebase that uses it.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this in #1695.

def load_all(stream: Union[str, IO[str]], Loader: Loader=...) -> Iterator[Any]: ...
def safe_load(stream: Union[str, IO[str]]) -> Any: ...
def safe_load_all(stream: Union[str, IO[str]]) -> Iterator[Any]: ...
def emit(events, stream=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=...): ...
def serialize_all(nodes, stream=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...): ...
def serialize(node, stream=..., Dumper=..., **kwds): ...
Expand Down