Skip to content

Commit e8c8b3b

Browse files
author
Mateusz Kurek
committed
Update os.path module to use file descriptor where possible
Fix #1653 Use `_FdOrPathType` when possible in `os.path` module.
1 parent b7dc041 commit e8c8b3b

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

stdlib/3/os/__init__.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,7 @@ if sys.version_info >= (3, 6):
183183
from builtins import _PathLike as PathLike # See comment in builtins
184184

185185
_PathType = path._PathType
186-
if sys.version_info >= (3, 3):
187-
_FdOrPathType = Union[int, _PathType]
188-
else:
189-
_FdOrPathType = _PathType
186+
_FdOrPathType = path._FdOrPathType
190187

191188
if sys.version_info >= (3, 6):
192189
class DirEntry(PathLike[AnyStr]):

stdlib/3/os/path.pyi

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ if sys.version_info >= (3, 6):
1717
else:
1818
_PathType = Union[bytes, Text]
1919

20+
if sys.version_info >= (3, 3):
21+
_FdOrPathType = Union[int, _PathType]
22+
else:
23+
_FdOrPathType = _PathType
24+
2025
# ----- os.path variables -----
2126
supports_unicode_filenames = False
2227
# aliases (also in os)
@@ -42,21 +47,21 @@ if sys.version_info >= (3, 5):
4247
def commonprefix(list: Sequence[AnyStr]) -> Any: ...
4348

4449
def dirname(path: AnyStr) -> AnyStr: ...
45-
def exists(path: _PathType) -> bool: ...
50+
def exists(path: _FdOrPathType) -> bool: ...
4651
def lexists(path: _PathType) -> bool: ...
4752
def expanduser(path: AnyStr) -> AnyStr: ...
4853
def expandvars(path: AnyStr) -> AnyStr: ...
4954

5055
# These return float if os.stat_float_times() == True,
5156
# but int is a subclass of float.
52-
def getatime(path: _PathType) -> float: ...
53-
def getmtime(path: _PathType) -> float: ...
54-
def getctime(path: _PathType) -> float: ...
57+
def getatime(path: _FdOrPathType) -> float: ...
58+
def getmtime(path: _FdOrPathType) -> float: ...
59+
def getctime(path: _FdOrPathType) -> float: ...
5560

56-
def getsize(path: _PathType) -> int: ...
61+
def getsize(path: _FdOrPathType) -> int: ...
5762
def isabs(path: _PathType) -> bool: ...
58-
def isfile(path: _PathType) -> bool: ...
59-
def isdir(path: _PathType) -> bool: ...
63+
def isfile(path: _FdOrPathType) -> bool: ...
64+
def isdir(path: _FdOrPathType) -> bool: ...
6065
def islink(path: _PathType) -> bool: ...
6166
def ismount(path: _PathType) -> bool: ...
6267

@@ -86,7 +91,7 @@ else:
8691
def realpath(filename: AnyStr) -> AnyStr: ...
8792
def relpath(path: AnyStr, start: _PathType = ...) -> AnyStr: ...
8893

89-
def samefile(path1: _PathType, path2: _PathType) -> bool: ...
94+
def samefile(path1: _FdOrPathType, path2: _FdOrPathType) -> bool: ...
9095
def sameopenfile(fp1: int, fp2: int) -> bool: ...
9196
# TODO
9297
# def samestat(stat1: stat_result,

0 commit comments

Comments
 (0)