Skip to content

Commit 15d3e3a

Browse files
committed
add stub for importlib.resources
Part of python#1965
1 parent ac70fdc commit 15d3e3a

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

stdlib/3/importlib/abc.pyi

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from abc import ABCMeta, abstractmethod
2+
import os
23
import sys
34
import types
4-
from typing import Any, Mapping, Optional, Sequence, Tuple, Union
5+
from typing import Any, IO, Mapping, Optional, Sequence, Tuple, Union
56

67
# Loader is exported from this module, but for circular import reasons
78
# exists in its own stub file (with ModuleSpec and ModuleType).
@@ -87,3 +88,16 @@ if sys.version_info >= (3, 3):
8788
def __init__(self, fullname: str, path: _Path) -> None: ...
8889
def get_data(self, path: _Path) -> bytes: ...
8990
def get_filename(self, fullname: str) -> _Path: ...
91+
92+
if sys.version_info >= (3, 7):
93+
_PathLike = Union[bytes, str, os.PathLike[Any]]
94+
95+
class ResourceReader(metaclass=abc.ABCMeta):
96+
@abc.abstractmethod
97+
def open_resource(self, resource: _PathLike) -> IO[bytes]: ...
98+
@abc.abstractmethod
99+
def resource_path(self, resource: _PathLike) -> str: ...
100+
@abc.abstractmethod
101+
def is_resource(self, name: str) -> bool: ...
102+
@abstractmethod
103+
def contents(self) -> iterator[str]: ...

stdlib/3/importlib/resources.pyi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
3+
from pathlib import Path
4+
from types import ModuleType
5+
from typing import ContextManager, Iterator, Union, BinaryIO, TextIO
6+
7+
Package = Union[str, ModuleType]
8+
Resource = Union[str, os.PathLike]
9+
10+
def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
11+
def open_text(package: Package,
12+
resource: Resource,
13+
encoding: str = ...,
14+
errors: str = ...) -> TextIO: ...
15+
def read_binary(package: Package, resource: Resource) -> bytes: ...
16+
def read_text(package: Package,
17+
resource: Resource,
18+
encoding: str = ...,
19+
errors: str = ...) -> str: ...
20+
def path(package: Package, resource: Resource) -> ContextManager[Path]: ...
21+
def is_resource(package: Package, name: str) -> bool: ...
22+
def contents(package: Package) -> Iterator[str]: ...

0 commit comments

Comments
 (0)