-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add a _typeshed.pyi file and a PathLike alias #4161
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
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
747758a
Add a _typeshed.pyi file and a PathLike alias
srittau e153624
Fix import
srittau 00f0069
Add missing typevar
srittau 7364d47
Split PathType in to StrPath and AnyPath
srittau 1558dd5
Fix problem with Python 3.5
srittau 8abae4b
Use Union instead of AnyStr
srittau e908adb
Fix comment
srittau 06131f5
Use AnyStr for PathLike
srittau 3bbe277
Use two PathLikes instead of AnyStr
srittau 04de71c
Add BytesPath
srittau fcb310e
Turn _typeshed into a package
srittau 9cad372
Comment wording improved
srittau 413edda
Add a Python 3.6 branch
srittau 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 hidden or 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,26 @@ | ||
# Utility types for typeshed | ||
|
||
# This module contains various common types to be used by typeshed. The | ||
# module and its types do not exist at runtime. You can use this module | ||
# outside of typeshed, but no API stability guarantees are made. To use | ||
# it in implementation (.py) files, the following construct must be used: | ||
# | ||
# from typing import TYPE_CHECKING | ||
# if TYPE_CHECKING: | ||
# from _typeshed import ... | ||
# | ||
# On Python versions < 3.10 and if "from __future__ import type_checking" | ||
# is not used, types from this module must be quoted. | ||
|
||
import sys | ||
from typing import AnyStr, Text, Union | ||
|
||
# StrPath and AnyPath can be used in places where a | ||
# path can be used instead of a string, starting with Python 3.6. | ||
if sys.version_info >= (3, 6): | ||
from os import PathLike | ||
StrPath = Union[str, PathLike[str]] | ||
AnyPath = Union[AnyStr, PathLike[AnyStr]] | ||
srittau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else: | ||
StrPath = Text | ||
AnyPath = Union[Text, bytes] |
This file contains hidden or 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 |
---|---|---|
@@ -1,22 +1,17 @@ | ||
import sys | ||
from typing import Any, AnyStr, Callable, ContextManager, Generic, IO, Optional, Text, Type, Union | ||
|
||
if sys.version_info >= (3, 6): | ||
from os import PathLike | ||
_Path = Union[str, bytes, PathLike[str], PathLike[bytes]] | ||
else: | ||
_Path = Union[Text, bytes] | ||
from _typeshed import AnyPath | ||
|
||
def replace_atomic(src: AnyStr, dst: AnyStr) -> None: ... | ||
def move_atomic(src: AnyStr, dst: AnyStr) -> None: ... | ||
class AtomicWriter(object): | ||
def __init__(self, path: _Path, mode: Text = ..., overwrite: bool = ...) -> None: ... | ||
def __init__(self, path: AnyPath, mode: Text = ..., overwrite: bool = ...) -> None: ... | ||
def open(self) -> ContextManager[IO[Any]]: ... | ||
def _open(self, get_fileobject: Callable[..., IO[AnyStr]]) -> ContextManager[IO[AnyStr]]: ... | ||
def get_fileobject(self, dir: Optional[_Path] = ..., **kwargs: Any) -> IO[Any]: ... | ||
def get_fileobject(self, dir: Optional[AnyPath] = ..., **kwargs: Any) -> IO[Any]: ... | ||
def sync(self, f: IO[Any]) -> None: ... | ||
def commit(self, f: IO[Any]) -> None: ... | ||
def rollback(self, f: IO[Any]) -> None: ... | ||
def atomic_write( | ||
path: _Path, writer_cls: Type[AtomicWriter] = ..., **cls_kwargs: object, | ||
path: AnyPath, writer_cls: Type[AtomicWriter] = ..., **cls_kwargs: object, | ||
) -> ContextManager[IO[Any]]: ... |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.