Skip to content
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

Add stub for toml #2355

Merged
merged 4 commits into from
Aug 3, 2018
Merged
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions third_party/2and3/toml.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Any, IO, Mapping, MutableMapping, Optional, Type, Union
import datetime


class TomlDecodeError(Exception): ...

class TomlTz(datetime.tzinfo):
Copy link
Member

Choose a reason for hiding this comment

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

Hm, this actually doesn't exist in master (https://github.com/uiri/toml/blob/master/toml/__init__.py), at least not at the top level.

I was looking at my installed version of toml before, which is apparently pretty out of date.

Copy link
Member

Choose a reason for hiding this comment

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

Relative to master we're also missing TomlArraySeparatorEncoder and a couple of other Encoder and Decoder classes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've deleted TomlTz, but I'd prefer not to add the other things -- they're not mentioned in the API reference in the README.rst. Let someone else finish this once they're documented. (The PR that prompted me to do this isn't even going to be merged.)

def __init__(self, toml_offset: str) -> None: ...

def load(f: Union[str, list, IO[str]], _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ...
Copy link
Member

Choose a reason for hiding this comment

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

The first two elements of the Union should be Text and List[Text]. The implementation looks like it should also support PathLike in 3.6+.

Copy link
Member

Choose a reason for hiding this comment

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

(But I don't feel strongly about whether we should add PathLike support in the stub if the library itself doesn't advertise that it supports PathLike. Your call.)

def loads(s: str, _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ...
Copy link
Member

Choose a reason for hiding this comment

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

The argument here should also be Text.


def dump(o: Mapping[str, Any], f: IO[str]) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

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

f can actually be any object with a write method. Perhaps we should go with the python/typing#564 of defining a simple protocol for this argument. In this case, it would just have def write(self, obj: str) -> Any: ....

def dumps(o: Mapping[str, Any]) -> str: ...