|
1 | 1 | 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 |
4 | 4 |
|
5 | 5 | if sys.version_info >= (3, 7):
|
6 | 6 | from py_compile import PycInvalidationMode
|
7 | 7 |
|
| 8 | +class _SupportsSearch(Protocol): |
| 9 | + def search(self, string: str) -> Any: ... |
| 10 | + |
8 | 11 | if sys.version_info >= (3, 9):
|
9 | 12 | def compile_dir(
|
10 |
| - dir: AnyPath, |
| 13 | + dir: StrPath, |
11 | 14 | maxlevels: Optional[int] = ...,
|
12 |
| - ddir: Optional[AnyPath] = ..., |
| 15 | + ddir: Optional[StrPath] = ..., |
13 | 16 | force: bool = ...,
|
14 |
| - rx: Optional[Pattern[Any]] = ..., |
| 17 | + rx: Optional[_SupportsSearch] = ..., |
15 | 18 | quiet: int = ...,
|
16 | 19 | legacy: bool = ...,
|
17 | 20 | optimize: int = ...,
|
18 | 21 | workers: int = ...,
|
19 | 22 | invalidation_mode: Optional[PycInvalidationMode] = ...,
|
20 | 23 | *,
|
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] = ..., |
24 | 27 | hardlink_dupes: bool = ...,
|
25 | 28 | ) -> int: ...
|
26 | 29 | def compile_file(
|
27 |
| - fullname: AnyPath, |
28 |
| - ddir: Optional[AnyPath] = ..., |
| 30 | + fullname: StrPath, |
| 31 | + ddir: Optional[StrPath] = ..., |
29 | 32 | force: bool = ...,
|
30 |
| - rx: Optional[Pattern[Any]] = ..., |
| 33 | + rx: Optional[_SupportsSearch] = ..., |
31 | 34 | quiet: int = ...,
|
32 | 35 | legacy: bool = ...,
|
33 | 36 | optimize: int = ...,
|
34 | 37 | invalidation_mode: Optional[PycInvalidationMode] = ...,
|
35 | 38 | *,
|
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] = ..., |
39 | 42 | hardlink_dupes: bool = ...,
|
40 | 43 | ) -> int: ...
|
41 | 44 |
|
42 | 45 | elif sys.version_info >= (3, 7):
|
43 | 46 | def compile_dir(
|
44 |
| - dir: AnyPath, |
| 47 | + dir: StrPath, |
45 | 48 | maxlevels: int = ...,
|
46 |
| - ddir: Optional[AnyPath] = ..., |
| 49 | + ddir: Optional[StrPath] = ..., |
47 | 50 | force: bool = ...,
|
48 |
| - rx: Optional[Pattern[Any]] = ..., |
| 51 | + rx: Optional[_SupportsSearch] = ..., |
49 | 52 | quiet: int = ...,
|
50 | 53 | legacy: bool = ...,
|
51 | 54 | optimize: int = ...,
|
52 | 55 | workers: int = ...,
|
53 | 56 | invalidation_mode: Optional[PycInvalidationMode] = ...,
|
54 | 57 | ) -> int: ...
|
55 | 58 | def compile_file(
|
56 |
| - fullname: AnyPath, |
57 |
| - ddir: Optional[AnyPath] = ..., |
| 59 | + fullname: StrPath, |
| 60 | + ddir: Optional[StrPath] = ..., |
58 | 61 | force: bool = ...,
|
59 |
| - rx: Optional[Pattern[Any]] = ..., |
| 62 | + rx: Optional[_SupportsSearch] = ..., |
60 | 63 | quiet: int = ...,
|
61 | 64 | legacy: bool = ...,
|
62 | 65 | optimize: int = ...,
|
63 | 66 | invalidation_mode: Optional[PycInvalidationMode] = ...,
|
64 | 67 | ) -> int: ...
|
65 | 68 |
|
66 | 69 | else:
|
67 |
| - # rx can be any object with a 'search' method; once we have Protocols we can change the type |
68 | 70 | def compile_dir(
|
69 |
| - dir: AnyPath, |
| 71 | + dir: StrPath, |
70 | 72 | maxlevels: int = ...,
|
71 |
| - ddir: Optional[AnyPath] = ..., |
| 73 | + ddir: Optional[StrPath] = ..., |
72 | 74 | force: bool = ...,
|
73 |
| - rx: Optional[Pattern[Any]] = ..., |
| 75 | + rx: Optional[_SupportsSearch] = ..., |
74 | 76 | quiet: int = ...,
|
75 | 77 | legacy: bool = ...,
|
76 | 78 | optimize: int = ...,
|
77 | 79 | workers: int = ...,
|
78 | 80 | ) -> int: ...
|
79 | 81 | def compile_file(
|
80 |
| - fullname: AnyPath, |
81 |
| - ddir: Optional[AnyPath] = ..., |
| 82 | + fullname: StrPath, |
| 83 | + ddir: Optional[StrPath] = ..., |
82 | 84 | force: bool = ...,
|
83 |
| - rx: Optional[Pattern[Any]] = ..., |
| 85 | + rx: Optional[_SupportsSearch] = ..., |
84 | 86 | quiet: int = ...,
|
85 | 87 | legacy: bool = ...,
|
86 | 88 | optimize: int = ...,
|
|
0 commit comments