Redo PathLike without importing os into builtins.

This commit is contained in:
Guido van Rossum
2017-03-21 10:50:10 -07:00
parent baa61a151b
commit 41561f11c7
2 changed files with 9 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ from typing import (
Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic,
Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat,
SupportsBytes, SupportsAbs, SupportsRound, IO, Union, ItemsView, KeysView, ValuesView,
ByteString, Optional
ByteString, Optional, AnyStr,
)
from abc import abstractmethod, ABCMeta
from types import TracebackType
@@ -799,8 +799,13 @@ def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ...
def oct(i: int) -> str: ... # TODO __index__
if sys.version_info >= (3, 6):
from pathlib import Path
def open(file: Union[str, bytes, int, Path], mode: str = 'r', buffering: int = -1, encoding: str = None,
# This class is to be exported as PathLike from os,
# but we define it here as _PathLike to avoid import cycle issues.
# See https://github.com/python/typeshed/pull/991#issuecomment-288160993
class _PathLike:
def __fspath__(self) -> AnyStr: ...
def open(file: Union[str, bytes, int, _PathLike], mode: str = 'r', buffering: int = -1, encoding: str = None,
errors: str = None, newline: str = None, closefd: bool = ...) -> IO[Any]: ...
else:
def open(file: Union[str, bytes, int], mode: str = 'r', buffering: int = -1, encoding: str = None,

View File

@@ -114,8 +114,7 @@ TMP_MAX = 0 # Undocumented, but used by tempfile
# ----- os classes (structures) -----
if sys.version_info >= (3, 6):
class PathLike:
def __fspath__(self) -> AnyStr: ...
from builtins import _PathLike as PathLike # See comment in builtins
_PathType = Union[bytes, Text]