1- # from jaraco.path 3.7.2
2-
3- from __future__ import annotations
1+ # from jaraco.path 3.7
42
53import functools
64import 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
127
138
149class Symlink (str ):
@@ -17,25 +12,29 @@ class Symlink(str):
1712 """
1813
1914
20- FilesSpec = Mapping [str , Union [str , bytes , Symlink , 'FilesSpec' ]]
15+ FilesSpec = Dict [str , Union [str , bytes , Symlink , 'FilesSpec' ]] # type: ignore
2116
2217
2318@runtime_checkable
2419class 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
3029
3130
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
3433
3534
3635def build (
3736 spec : FilesSpec ,
38- prefix : str | TreeMaker = pathlib .Path (),
37+ prefix : Union [ str , TreeMaker ] = pathlib .Path (), # type: ignore
3938):
4039 """
4140 Build a set of files/directories, as described by the spec.
@@ -67,24 +66,23 @@ def build(
6766
6867
6968@functools .singledispatch
70- def create (content : str | bytes | FilesSpec , path : TreeMaker ) -> None :
69+ def create (content : Union [ str , bytes , FilesSpec ] , path ) :
7170 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
7472
7573
7674@create .register
77- def _ (content : bytes , path : TreeMaker ) -> None :
75+ def _ (content : bytes , path ) :
7876 path .write_bytes (content )
7977
8078
8179@create .register
82- def _ (content : str , path : TreeMaker ) -> None :
80+ def _ (content : str , path ) :
8381 path .write_text (content , encoding = 'utf-8' )
8482
8583
8684@create .register
87- def _ (content : Symlink , path : TreeMaker ) -> None :
85+ def _ (content : Symlink , path ) :
8886 path .symlink_to (content )
8987
9088
0 commit comments