Skip to content

Commit 60975a3

Browse files
authored
compileall: rx argument, str paths (#5172)
1 parent 472485d commit 60975a3

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

stdlib/compileall.pyi

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,88 @@
11
import sys
2-
from _typeshed import AnyPath
3-
from typing import Any, Optional, Pattern
2+
from _typeshed import StrPath
3+
from typing import Any, Optional, Protocol
44

55
if sys.version_info >= (3, 7):
66
from py_compile import PycInvalidationMode
77

8+
class _SupportsSearch(Protocol):
9+
def search(self, string: str) -> Any: ...
10+
811
if sys.version_info >= (3, 9):
912
def compile_dir(
10-
dir: AnyPath,
13+
dir: StrPath,
1114
maxlevels: Optional[int] = ...,
12-
ddir: Optional[AnyPath] = ...,
15+
ddir: Optional[StrPath] = ...,
1316
force: bool = ...,
14-
rx: Optional[Pattern[Any]] = ...,
17+
rx: Optional[_SupportsSearch] = ...,
1518
quiet: int = ...,
1619
legacy: bool = ...,
1720
optimize: int = ...,
1821
workers: int = ...,
1922
invalidation_mode: Optional[PycInvalidationMode] = ...,
2023
*,
21-
stripdir: Optional[str] = ..., # TODO: change to Optional[AnyPath] once https://bugs.python.org/issue40447 is resolved
22-
prependdir: Optional[AnyPath] = ...,
23-
limit_sl_dest: Optional[AnyPath] = ...,
24+
stripdir: Optional[str] = ..., # TODO: change to Optional[StrPath] once https://bugs.python.org/issue40447 is resolved
25+
prependdir: Optional[StrPath] = ...,
26+
limit_sl_dest: Optional[StrPath] = ...,
2427
hardlink_dupes: bool = ...,
2528
) -> int: ...
2629
def compile_file(
27-
fullname: AnyPath,
28-
ddir: Optional[AnyPath] = ...,
30+
fullname: StrPath,
31+
ddir: Optional[StrPath] = ...,
2932
force: bool = ...,
30-
rx: Optional[Pattern[Any]] = ...,
33+
rx: Optional[_SupportsSearch] = ...,
3134
quiet: int = ...,
3235
legacy: bool = ...,
3336
optimize: int = ...,
3437
invalidation_mode: Optional[PycInvalidationMode] = ...,
3538
*,
36-
stripdir: Optional[str] = ..., # TODO: change to Optional[AnyPath] once https://bugs.python.org/issue40447 is resolved
37-
prependdir: Optional[AnyPath] = ...,
38-
limit_sl_dest: Optional[AnyPath] = ...,
39+
stripdir: Optional[str] = ..., # TODO: change to Optional[StrPath] once https://bugs.python.org/issue40447 is resolved
40+
prependdir: Optional[StrPath] = ...,
41+
limit_sl_dest: Optional[StrPath] = ...,
3942
hardlink_dupes: bool = ...,
4043
) -> int: ...
4144

4245
elif sys.version_info >= (3, 7):
4346
def compile_dir(
44-
dir: AnyPath,
47+
dir: StrPath,
4548
maxlevels: int = ...,
46-
ddir: Optional[AnyPath] = ...,
49+
ddir: Optional[StrPath] = ...,
4750
force: bool = ...,
48-
rx: Optional[Pattern[Any]] = ...,
51+
rx: Optional[_SupportsSearch] = ...,
4952
quiet: int = ...,
5053
legacy: bool = ...,
5154
optimize: int = ...,
5255
workers: int = ...,
5356
invalidation_mode: Optional[PycInvalidationMode] = ...,
5457
) -> int: ...
5558
def compile_file(
56-
fullname: AnyPath,
57-
ddir: Optional[AnyPath] = ...,
59+
fullname: StrPath,
60+
ddir: Optional[StrPath] = ...,
5861
force: bool = ...,
59-
rx: Optional[Pattern[Any]] = ...,
62+
rx: Optional[_SupportsSearch] = ...,
6063
quiet: int = ...,
6164
legacy: bool = ...,
6265
optimize: int = ...,
6366
invalidation_mode: Optional[PycInvalidationMode] = ...,
6467
) -> int: ...
6568

6669
else:
67-
# rx can be any object with a 'search' method; once we have Protocols we can change the type
6870
def compile_dir(
69-
dir: AnyPath,
71+
dir: StrPath,
7072
maxlevels: int = ...,
71-
ddir: Optional[AnyPath] = ...,
73+
ddir: Optional[StrPath] = ...,
7274
force: bool = ...,
73-
rx: Optional[Pattern[Any]] = ...,
75+
rx: Optional[_SupportsSearch] = ...,
7476
quiet: int = ...,
7577
legacy: bool = ...,
7678
optimize: int = ...,
7779
workers: int = ...,
7880
) -> int: ...
7981
def compile_file(
80-
fullname: AnyPath,
81-
ddir: Optional[AnyPath] = ...,
82+
fullname: StrPath,
83+
ddir: Optional[StrPath] = ...,
8284
force: bool = ...,
83-
rx: Optional[Pattern[Any]] = ...,
85+
rx: Optional[_SupportsSearch] = ...,
8486
quiet: int = ...,
8587
legacy: bool = ...,
8688
optimize: int = ...,

0 commit comments

Comments
 (0)