Skip to content

Commit 2dd85c3

Browse files
JelleZijlstramatthiaskramm
authored andcommitted
move os.stat_result into posix stub (#1818)
This removes the circular dependency between the os and posix stub, which is somehow triggering python/mypy#4442. We should ideally fix the mypy bug, but since it's easy enough to fix the import cycle, we might as well do that too.
1 parent 8175130 commit 2dd85c3

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

stdlib/3/os/__init__.pyi

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# Stubs for os
22
# Ron Murawski <[email protected]>
33

4-
from builtins import OSError as error
54
from io import TextIOWrapper as _TextIOWrapper
65
import sys
76
from typing import (
87
Mapping, MutableMapping, Dict, List, Any, Tuple, IO, Iterable, Iterator, overload, Union, AnyStr,
98
Optional, Generic, Set, Callable, Text, Sequence, NamedTuple, TypeVar, ContextManager
109
)
11-
from . import path as path
1210
from mypy_extensions import NoReturn
1311

12+
# Re-exported names from other modules.
13+
from builtins import OSError as error
14+
from posix import stat_result as stat_result
15+
from . import path as path
16+
1417
_T = TypeVar('_T')
1518

1619
# ----- os variables -----
@@ -216,49 +219,6 @@ elif sys.version_info >= (3, 5):
216219
def stat(self) -> stat_result: ...
217220

218221

219-
class stat_result:
220-
# For backward compatibility, the return value of stat() is also
221-
# accessible as a tuple of at least 10 integers giving the most important
222-
# (and portable) members of the stat structure, in the order st_mode,
223-
# st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime,
224-
# st_ctime. More items may be added at the end by some implementations.
225-
226-
st_mode: int # protection bits,
227-
st_ino: int # inode number,
228-
st_dev: int # device,
229-
st_nlink: int # number of hard links,
230-
st_uid: int # user id of owner,
231-
st_gid: int # group id of owner,
232-
st_size: int # size of file, in bytes,
233-
st_atime: float # time of most recent access,
234-
st_mtime: float # time of most recent content modification,
235-
st_ctime: float # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows)
236-
237-
if sys.version_info >= (3, 3):
238-
st_atime_ns: int # time of most recent access, in nanoseconds
239-
st_mtime_ns: int # time of most recent content modification in nanoseconds
240-
st_ctime_ns: int # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) in nanoseconds
241-
242-
# not documented
243-
def __init__(self, tuple: Tuple[int, ...]) -> None: ...
244-
245-
# On some Unix systems (such as Linux), the following attributes may also
246-
# be available:
247-
st_blocks: int # number of blocks allocated for file
248-
st_blksize: int # filesystem blocksize
249-
st_rdev: int # type of device if an inode device
250-
st_flags: int # user defined flags for file
251-
252-
# On other Unix systems (such as FreeBSD), the following attributes may be
253-
# available (but may be only filled out if root tries to use them):
254-
st_gen: int # file generation number
255-
st_birthtime: int # time of file creation
256-
257-
# On Mac OS systems, the following attributes may also be available:
258-
st_rsize: int
259-
st_creator: int
260-
st_type: int
261-
262222
class statvfs_result: # Unix only
263223
f_bsize: int
264224
f_frsize: int

stdlib/3/posix.pyi

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,50 @@
44

55
import sys
66
import typing
7-
from os import stat_result
8-
from typing import NamedTuple
7+
from typing import NamedTuple, Tuple
8+
9+
class stat_result:
10+
# For backward compatibility, the return value of stat() is also
11+
# accessible as a tuple of at least 10 integers giving the most important
12+
# (and portable) members of the stat structure, in the order st_mode,
13+
# st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime,
14+
# st_ctime. More items may be added at the end by some implementations.
15+
16+
st_mode: int # protection bits,
17+
st_ino: int # inode number,
18+
st_dev: int # device,
19+
st_nlink: int # number of hard links,
20+
st_uid: int # user id of owner,
21+
st_gid: int # group id of owner,
22+
st_size: int # size of file, in bytes,
23+
st_atime: float # time of most recent access,
24+
st_mtime: float # time of most recent content modification,
25+
st_ctime: float # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows)
26+
27+
if sys.version_info >= (3, 3):
28+
st_atime_ns: int # time of most recent access, in nanoseconds
29+
st_mtime_ns: int # time of most recent content modification in nanoseconds
30+
st_ctime_ns: int # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) in nanoseconds
31+
32+
# not documented
33+
def __init__(self, tuple: Tuple[int, ...]) -> None: ...
34+
35+
# On some Unix systems (such as Linux), the following attributes may also
36+
# be available:
37+
st_blocks: int # number of blocks allocated for file
38+
st_blksize: int # filesystem blocksize
39+
st_rdev: int # type of device if an inode device
40+
st_flags: int # user defined flags for file
41+
42+
# On other Unix systems (such as FreeBSD), the following attributes may be
43+
# available (but may be only filled out if root tries to use them):
44+
st_gen: int # file generation number
45+
st_birthtime: int # time of file creation
46+
47+
# On Mac OS systems, the following attributes may also be available:
48+
st_rsize: int
49+
st_creator: int
50+
st_type: int
951

1052
if sys.version_info >= (3, 3):
1153
uname_result = NamedTuple('uname_result', [('sysname', str), ('nodename', str),

0 commit comments

Comments
 (0)