Skip to content

Commit 6a06dd4

Browse files
authored
Revert "Make os.stat_result and friends NamedTuples" (#1113)
* Revert "Added missing attributes of typing.Generator and typing.AsyncGenerator (#886)" This reverts commit 8b26422.
1 parent 8b26422 commit 6a06dd4

File tree

2 files changed

+51
-99
lines changed

2 files changed

+51
-99
lines changed

stdlib/2/os/__init__.pyi

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# created from https://docs.python.org/2/library/os.html
22

3-
import sys
43
from typing import (
54
Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr,
65
Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple
@@ -95,58 +94,10 @@ WUNTRACED = 0 # Unix only
9594

9695
TMP_MAX = 0 # Undocumented, but used by tempfile
9796
_PathType = Union[bytes, Text]
98-
99-
class stat_result(NamedTuple('stat_result', [
100-
('st_mode', int),
101-
('st_ino', int),
102-
('st_dev', int),
103-
('st_nlink', int),
104-
('st_uid', int),
105-
('st_gid', int),
106-
('st_size', int),
107-
('st_atime', float),
108-
('st_mtime', float),
109-
('st_ctime', float)])):
110-
111-
# For backward compatibility, the return value of stat() is also
112-
# accessible as a tuple of at least 10 integers giving the most important
113-
# (and portable) members of the stat structure, in the order st_mode,
114-
# st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime,
115-
# st_ctime. More items may be added at the end by some implementations.
116-
117-
if sys.version_info >= (3, 3):
118-
st_atime_ns = ... # type: int
119-
st_mtime_ns = ... # type: int
120-
st_ctime_ns = ... # type: int
121-
122-
# On some Unix systems (such as Linux), the following attributes may also
123-
# be available:
124-
st_blocks = ... # type: int
125-
st_blksize = ... # type: int
126-
st_rdev = ... # type: int
127-
st_flags = ... # type: int
128-
129-
# On other Unix systems (such as FreeBSD), the following attributes may be
130-
# available (but may be only filled out if root tries to use them):
131-
st_gen = ... # type: int
132-
st_birthtime = ... # type: int
133-
134-
# On Mac OS systems, the following attributes may also be available:
135-
st_rsize = ... # type: int
136-
st_creator = ... # type: int
137-
st_type = ... # type: int
138-
139-
statvfs_result = NamedTuple('statvfs_result', [
140-
('f_bsize', int),
141-
('f_frsize', int),
142-
('f_blocks', int),
143-
('f_bfree', int),
144-
('f_bavail', int),
145-
('f_files', int),
146-
('f_ffree', int),
147-
('f_favail', int),
148-
('f_flag', int),
149-
('f_namemax', int)])
97+
_StatVFS = NamedTuple('_StatVFS', [('f_bsize', int), ('f_frsize', int), ('f_blocks', int),
98+
('f_bfree', int), ('f_bavail', int), ('f_files', int),
99+
('f_ffree', int), ('f_favail', int), ('f_flag', int),
100+
('f_namemax', int)])
150101
def ctermid() -> str: ... # Unix only
151102
def getegid() -> int: ... # Unix only
152103
def geteuid() -> int: ... # Unix only
@@ -189,8 +140,8 @@ def fchmod(fd: int, mode: int) -> None: ... # Unix only
189140
def fchown(fd: int, uid: int, gid: int) -> None: ... # Unix only
190141
def fdatasync(fd: int) -> None: ... # Unix only, not Mac
191142
def fpathconf(fd: int, name: Union[str, int]) -> int: ... # Unix only
192-
def fstat(fd: int) -> stat_result: ...
193-
def fstatvfs(fd: int) -> statvfs_result: ... # Unix only
143+
def fstat(fd: int) -> Any: ...
144+
def fstatvfs(fd: int) -> _StatVFS: ... # Unix only
194145
def fsync(fd: int) -> None: ...
195146
def ftruncate(fd: int, length: int) -> None: ... # Unix only
196147
def isatty(fd: int) -> bool: ... # Unix only
@@ -217,7 +168,7 @@ def lchmod(path: _PathType, mode: int) -> None: ... # Unix only
217168
def lchown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only
218169
def link(src: _PathType, link_name: _PathType) -> None: ...
219170
def listdir(path: AnyStr) -> List[AnyStr]: ...
220-
def lstat(path: _PathType) -> stat_result: ...
171+
def lstat(path: _PathType) -> Any: ...
221172
def mkfifo(path: _PathType, mode: int = ...) -> None: ... # Unix only
222173
def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ...
223174
def major(device: int) -> int: ...
@@ -232,12 +183,12 @@ def removedirs(path: _PathType) -> None: ...
232183
def rename(src: _PathType, dst: _PathType) -> None: ...
233184
def renames(old: _PathType, new: _PathType) -> None: ...
234185
def rmdir(path: _PathType) -> None: ...
186+
def stat(path: _PathType) -> Any: ...
235187
@overload
236-
def stat_float_times(newvalue: bool) -> None: ...
188+
def stat_float_times(newvalue: bool = ...) -> None: ...
237189
@overload
238190
def stat_float_times() -> bool: ...
239-
def stat(path: _PathType) -> stat_result: ...
240-
def statvfs(path: _PathType) -> statvfs_result: ... # Unix only
191+
def statvfs(path: _PathType) -> _StatVFS: ... # Unix only
241192
def symlink(source: _PathType, link_name: _PathType) -> None: ...
242193
def unlink(path: _PathType) -> None: ...
243194
def utime(path: _PathType, times: Optional[Tuple[float, float]]) -> None: ...

stdlib/3/os/__init__.pyi

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from io import TextIOWrapper as _TextIOWrapper
88
import sys
99
from typing import (
1010
Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr,
11-
Optional, Generic, Set, Callable, Text, Sequence, NamedTuple
11+
Optional, Generic, Set, Callable, Text, Sequence
1212
)
1313
from . import path
1414
from mypy_extensions import NoReturn
@@ -145,57 +145,61 @@ elif sys.version_info >= (3, 5):
145145
def is_symlink(self) -> bool: ...
146146
def stat(self) -> stat_result: ...
147147

148-
class stat_result(NamedTuple('stat_result', [
149-
('st_mode', int),
150-
('st_ino', int),
151-
('st_dev', int),
152-
('st_nlink', int),
153-
('st_uid', int),
154-
('st_gid', int),
155-
('st_size', int),
156-
('st_atime', float),
157-
('st_mtime', float),
158-
('st_ctime', float)])):
159148

149+
class stat_result:
160150
# For backward compatibility, the return value of stat() is also
161151
# accessible as a tuple of at least 10 integers giving the most important
162152
# (and portable) members of the stat structure, in the order st_mode,
163153
# st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime,
164154
# st_ctime. More items may be added at the end by some implementations.
165155

156+
st_mode = 0 # protection bits,
157+
st_ino = 0 # inode number,
158+
st_dev = 0 # device,
159+
st_nlink = 0 # number of hard links,
160+
st_uid = 0 # user id of owner,
161+
st_gid = 0 # group id of owner,
162+
st_size = 0 # size of file, in bytes,
163+
st_atime = 0.0 # time of most recent access,
164+
st_mtime = 0.0 # time of most recent content modification,
165+
st_ctime = 0.0 # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows)
166+
166167
if sys.version_info >= (3, 3):
167-
st_atime_ns = ... # type: int
168-
st_mtime_ns = ... # type: int
169-
st_ctime_ns = ... # type: int
168+
st_atime_ns = 0 # time of most recent access, in nanoseconds
169+
st_mtime_ns = 0 # time of most recent content modification in nanoseconds
170+
st_ctime_ns = 0 # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) in nanoseconds
171+
172+
# not documented
173+
def __init__(self, tuple: Tuple[int, ...]) -> None: ...
170174

171175
# On some Unix systems (such as Linux), the following attributes may also
172176
# be available:
173-
st_blocks = ... # type: int
174-
st_blksize = ... # type: int
175-
st_rdev = ... # type: int
176-
st_flags = ... # type: int
177+
st_blocks = 0 # number of blocks allocated for file
178+
st_blksize = 0 # filesystem blocksize
179+
st_rdev = 0 # type of device if an inode device
180+
st_flags = 0 # user defined flags for file
177181

178182
# On other Unix systems (such as FreeBSD), the following attributes may be
179183
# available (but may be only filled out if root tries to use them):
180-
st_gen = ... # type: int
181-
st_birthtime = ... # type: int
184+
st_gen = 0 # file generation number
185+
st_birthtime = 0 # time of file creation
182186

183187
# On Mac OS systems, the following attributes may also be available:
184-
st_rsize = ... # type: int
185-
st_creator = ... # type: int
186-
st_type = ... # type: int
187-
188-
statvfs_result = NamedTuple('statvfs_result', [
189-
('f_bsize', int),
190-
('f_frsize', int),
191-
('f_blocks', int),
192-
('f_bfree', int),
193-
('f_bavail', int),
194-
('f_files', int),
195-
('f_ffree', int),
196-
('f_favail', int),
197-
('f_flag', int),
198-
('f_namemax', int)])
188+
st_rsize = 0
189+
st_creator = 0
190+
st_type = 0
191+
192+
class statvfs_result: # Unix only
193+
f_bsize = 0
194+
f_frsize = 0
195+
f_blocks = 0
196+
f_bfree = 0
197+
f_bavail = 0
198+
f_files = 0
199+
f_ffree = 0
200+
f_favail = 0
201+
f_flag = 0
202+
f_namemax = 0
199203

200204
# ----- os function stubs -----
201205
if sys.version_info >= (3, 6):
@@ -321,11 +325,8 @@ if sys.version_info >= (3, 5):
321325
def scandir(path: str = ...) -> Iterator[DirEntry[str]]: ...
322326
@overload
323327
def scandir(path: bytes) -> Iterator[DirEntry[bytes]]: ...
324-
@overload
325-
def stat_float_times(newvalue: bool) -> None: ...
326-
@overload
327-
def stat_float_times() -> bool: ...
328328
def stat(path: _PathType) -> stat_result: ...
329+
def stat_float_times(newvalue: Union[bool, None] = ...) -> bool: ...
329330
def statvfs(path: _PathType) -> statvfs_result: ... # Unix only
330331
def symlink(source: _PathType, link_name: _PathType,
331332
target_is_directory: bool = ...) -> None:

0 commit comments

Comments
 (0)