Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add stub for importlib.resources #1993

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
Mar 29, 2018
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions stdlib/3.7/importlib/resources.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os

from pathlib import Path
from types import ModuleType
from typing import ContextManager, Iterator, Union, BinaryIO, TextIO

Package = Union[str, ModuleType]
Resource = Union[str, os.PathLike]

def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
def open_text(package: Package,
resource: Resource,
encoding: str = ...,
errors: str = ...) -> TextIO: ...
def read_binary(package: Package, resource: Resource) -> bytes: ...
def read_text(package: Package,
resource: Resource,
encoding: str = ...,
errors: str = ...) -> str: ...
def path(package: Package, resource: Resource) -> ContextManager[Path]: ...
def is_resource(package: Package, name: str) -> bool: ...
def contents(package: Package) -> Iterator[str]: ...
16 changes: 15 additions & 1 deletion stdlib/3/importlib/abc.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from abc import ABCMeta, abstractmethod
import os
import sys
import types
from typing import Any, Mapping, Optional, Sequence, Tuple, Union
from typing import Any, IO, Iterator, Mapping, Optional, Sequence, Tuple, Union

# Loader is exported from this module, but for circular import reasons
# exists in its own stub file (with ModuleSpec and ModuleType).
Expand Down Expand Up @@ -87,3 +88,16 @@ if sys.version_info >= (3, 3):
def __init__(self, fullname: str, path: _Path) -> None: ...
def get_data(self, path: _Path) -> bytes: ...
def get_filename(self, fullname: str) -> _Path: ...

if sys.version_info >= (3, 7):
_PathLike = Union[bytes, str, os.PathLike[Any]]

class ResourceReader(metaclass=ABCMeta):
@abstractmethod
def open_resource(self, resource: _PathLike) -> IO[bytes]: ...
@abstractmethod
def resource_path(self, resource: _PathLike) -> str: ...
@abstractmethod
def is_resource(self, name: str) -> bool: ...
@abstractmethod
def contents(self) -> Iterator[str]: ...