Skip to content

Commit 41561f1

Browse files
author
Guido van Rossum
committed
Redo PathLike without importing os into builtins.
1 parent baa61a1 commit 41561f1

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎stdlib/3/builtins.pyi‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from typing import (
55
Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic,
66
Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat,
77
SupportsBytes, SupportsAbs, SupportsRound, IO, Union, ItemsView, KeysView, ValuesView,
8-
ByteString, Optional
8+
ByteString, Optional, AnyStr,
99
)
1010
from abc import abstractmethod, ABCMeta
1111
from types import TracebackType
@@ -799,8 +799,13 @@ def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ...
799799
def oct(i: int) -> str: ... # TODO __index__
800800

801801
if sys.version_info >= (3, 6):
802-
from pathlib import Path
803-
def open(file: Union[str, bytes, int, Path], mode: str = 'r', buffering: int = -1, encoding: str = None,
802+
# This class is to be exported as PathLike from os,
803+
# but we define it here as _PathLike to avoid import cycle issues.
804+
# See https://github.com/python/typeshed/pull/991#issuecomment-288160993
805+
class _PathLike:
806+
def __fspath__(self) -> AnyStr: ...
807+
808+
def open(file: Union[str, bytes, int, _PathLike], mode: str = 'r', buffering: int = -1, encoding: str = None,
804809
errors: str = None, newline: str = None, closefd: bool = ...) -> IO[Any]: ...
805810
else:
806811
def open(file: Union[str, bytes, int], mode: str = 'r', buffering: int = -1, encoding: str = None,

‎stdlib/3/os/__init__.pyi‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ TMP_MAX = 0 # Undocumented, but used by tempfile
114114

115115
# ----- os classes (structures) -----
116116
if sys.version_info >= (3, 6):
117-
class PathLike:
118-
def __fspath__(self) -> AnyStr: ...
117+
from builtins import _PathLike as PathLike # See comment in builtins
119118

120119
_PathType = Union[bytes, Text]
121120

0 commit comments

Comments
 (0)