8000 pathlib: fix most typing issues · python/cpython@d83531f · GitHub
[go: up one dir, main page]

Skip to content

Commit d83531f

Browse files
committed
pathlib: fix most typing issues
1 parent b952ab0 commit d83531f

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Lib/pathlib/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
from stat import S_ISDIR, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
1818
from _collections_abc import Sequence
1919

20+
# types
21+
if False:
22+
from types import ModuleType
23+
24+
pwd: ModuleType | None
25+
grp: ModuleType | None
26+
2027
try:
2128
import pwd
2229
except ImportError:
@@ -26,7 +33,7 @@
2633
except ImportError:
2734
grp = None
2835

29-
from pathlib._os import (
36+
from ._os import (
3037
PathInfo, DirEntryInfo,
3138
ensure_different_files, ensure_distinct_paths,
3239
copyfile2, copyfileobj, magic_open, copy_info,

Lib/pathlib/_os.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@
77
import io
88
import os
99
import sys
10+
11+
# typing
12+
if False:
13+
from collections.abc import Callable
14+
from types import ModuleType
15+
16+
type CopyFunc = Callable[[int, int], None]
17+
18+
fcntl: ModuleType | None
19+
posix: ModuleType | None
20+
_winapi: ModuleType | None
21+
_ficlone: CopyFunc | None
22+
_fcopyfile: CopyFunc | None
23+
_copy_file_range: CopyFunc | None
24+
_sendfile: CopyFunc | None
25+
copyfile2: CopyFunc | None
26+
1027
try:
1128
import fcntl
1229
except ImportError:

Lib/pathlib/types.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
from abc import ABC, abstractmethod
1414
from collections.abc import Callable, Iterator, Sequence
1515
from glob import _PathGlobber
16-
from pathlib._os import magic_open, ensure_distinct_paths, ensure_different_files, copyfileobj
17-
from pathlib import PurePath, Path
1816
from typing import Protocol, runtime_checkable
1917

18+
from . import PurePath, Path
19+
from ._os import magic_open, ensure_distinct_paths, ensure_different_files, copyfileobj
20+
2021
# typing
2122
if False:
2223
from typing import Any, BinaryIO, Literal, Self
@@ -308,7 +309,9 @@ def walk(
308309
follow_symlinks: bool = False,
309310
) -> Iterator[tuple[Self, list[str], list[str]]]:
310311
"""Walk the directory tree from this directory, similar to os.walk()."""
311-
paths = [self]
312+
dirnames: list[str]
313+
filenames: list[str]
314+
paths: list[Self | tuple[Self, list[str], list[str]]] = [self]
312315
while paths:
313316
path = paths.pop()
314317
if isinstance(path, tuple):

0 commit comments

Comments
 (0)
0