1
- # from jaraco.path 3.7.2
2
-
3
- from __future__ import annotations
1
+ # from jaraco.path 3.7
4
2
5
3
import functools
6
4
import pathlib
7
- from collections .abc import Mapping
8
- from typing import TYPE_CHECKING , Protocol , Union , runtime_checkable
9
-
10
- if TYPE_CHECKING :
11
- from typing_extensions import Self
5
+ from typing import Dict , Protocol , Union
6
+ from typing import runtime_checkable
12
7
13
8
14
9
class Symlink (str ):
@@ -17,25 +12,29 @@ class Symlink(str):
17
12
"""
18
13
19
14
20
- FilesSpec = Mapping [str , Union [str , bytes , Symlink , 'FilesSpec' ]]
15
+ FilesSpec = Dict [str , Union [str , bytes , Symlink , 'FilesSpec' ]] # type: ignore
21
16
22
17
23
18
@runtime_checkable
24
19
class TreeMaker (Protocol ):
25
- def __truediv__ (self , other , / ) -> Self : ...
26
- def mkdir (self , * , exist_ok ) -> object : ...
27
- def write_text (self , content , / , * , encoding ) -> object : ...
28
- def write_bytes (self , content , / ) -> object : ...
29
- def symlink_to (self , target , / ) -> object : ...
20
+ def __truediv__ (self , * args , ** kwargs ): ... # pragma: no cover
21
+
22
+ def mkdir (self , ** kwargs ): ... # pragma: no cover
23
+
24
+ def write_text (self , content , ** kwargs ): ... # pragma: no cover
25
+
26
+ def write_bytes (self , content ): ... # pragma: no cover
27
+
28
+ def symlink_to (self , target ): ... # pragma: no cover
30
29
31
30
32
- def _ensure_tree_maker (obj : str | TreeMaker ) -> TreeMaker :
33
- return obj if isinstance (obj , TreeMaker ) else pathlib .Path (obj )
31
+ def _ensure_tree_maker (obj : Union [ str , TreeMaker ] ) -> TreeMaker :
32
+ return obj if isinstance (obj , TreeMaker ) else pathlib .Path (obj ) # type: ignore
34
33
35
34
36
35
def build (
37
36
spec : FilesSpec ,
38
- prefix : str | TreeMaker = pathlib .Path (),
37
+ prefix : Union [ str , TreeMaker ] = pathlib .Path (), # type: ignore
39
38
):
40
39
"""
41
40
Build a set of files/directories, as described by the spec.
@@ -67,24 +66,23 @@ def build(
67
66
68
67
69
68
@functools .singledispatch
70
- def create (content : str | bytes | FilesSpec , path : TreeMaker ) -> None :
69
+ def create (content : Union [ str , bytes , FilesSpec ] , path ) :
71
70
path .mkdir (exist_ok = True )
72
- # Mypy only looks at the signature of the main singledispatch method. So it must contain the complete Union
73
- build (content , prefix = path ) # type: ignore[arg-type] # python/mypy#11727
71
+ build (content , prefix = path ) # type: ignore
74
72
75
73
76
74
@create .register
77
- def _ (content : bytes , path : TreeMaker ) -> None :
75
+ def _ (content : bytes , path ) :
78
76
path .write_bytes (content )
79
77
80
78
81
79
@create .register
82
- def _ (content : str , path : TreeMaker ) -> None :
80
+ def _ (content : str , path ) :
83
81
path .write_text (content , encoding = 'utf-8' )
84
82
85
83
86
84
@create .register
87
- def _ (content : Symlink , path : TreeMaker ) -> None :
85
+ def _ (content : Symlink , path ) :
88
86
path .symlink_to (content )
89
87
90
88
0 commit comments