Skip to content

Commit bc1dfc0

Browse files
sispyajo
authored andcommitted
build(typing): add missing type hints
1 parent 59b8d6d commit bc1dfc0

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

copier/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ def run_update(
10021002
return worker
10031003

10041004

1005-
def _remove_old_files(prefix: Path, cmp: dircmp, rm_common: bool = False):
1005+
def _remove_old_files(prefix: Path, cmp: dircmp, rm_common: bool = False) -> None:
10061006
"""Remove files and directories only found in "old" template.
10071007
10081008
This is an internal helper method used to process a comparison of 2

copier/user_data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
# TODO Remove these two functions as well as DEFAULT_DATA in a future release
30-
def _now():
30+
def _now() -> datetime:
3131
warnings.warn(
3232
"'now' will be removed in a future release of Copier.\n"
3333
"Please use this instead: {{ '%Y-%m-%d %H:%M:%S' | strftime }}\n"
@@ -37,7 +37,7 @@ def _now():
3737
return datetime.utcnow()
3838

3939

40-
def _make_secret():
40+
def _make_secret() -> str:
4141
warnings.warn(
4242
"'make_secret' will be removed in a future release of Copier.\n"
4343
"Please use this instead: {{ 999999999999999999999999999999999|ans_random|hash('sha512') }}\n"

copier/vcs.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
from packaging import version
1111
from packaging.version import InvalidVersion, Version
1212
from plumbum import TF, ProcessExecutionError, colors, local
13+
from plumbum.machines import LocalCommand
1314

1415
from .errors import DirtyLocalWarning, ShallowCloneWarning
1516
from .types import OptBool, OptStr, OptStrOrPath, StrOrPath
1617

1718

18-
def get_git(context_dir: OptStrOrPath = None):
19+
def get_git(context_dir: OptStrOrPath = None) -> LocalCommand:
1920
"""Gets `git` command, or fails if it's not available"""
2021
command = local["git"]
2122
if context_dir:
2223
command = command["-C", context_dir]
2324
return command
2425

2526

26-
def get_git_version():
27+
def get_git_version() -> Version:
2728
git = get_git()
2829

2930
return Version(re.findall(r"\d+\.\d+\.\d+", git("version"))[0])

tests/test_subdirectory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .helpers import BRACKET_ENVOPS_JSON, SUFFIX_TMPL, build_file_tree
1313

1414

15-
def git_init(message="hello world"):
15+
def git_init(message="hello world") -> None:
1616
git("init")
1717
git("config", "user.name", "Copier Test")
1818
git("config", "user.email", "test@copier")

tests/test_symlinks.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .helpers import build_file_tree
1313

1414

15-
def test_copy_symlink(tmp_path_factory):
15+
def test_copy_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
1616
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
1717
# Prepare repo bundle
1818
repo = src / "repo"
@@ -47,7 +47,7 @@ def test_copy_symlink(tmp_path_factory):
4747
assert readlink(dst / "symlink.txt") == Path("target.txt")
4848

4949

50-
def test_copy_symlink_templated_name(tmp_path_factory):
50+
def test_copy_symlink_templated_name(tmp_path_factory: pytest.TempPathFactory) -> None:
5151
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
5252
# Prepare repo bundle
5353
repo = src / "repo"
@@ -83,7 +83,9 @@ def test_copy_symlink_templated_name(tmp_path_factory):
8383
assert readlink(dst / "symlink.txt") == Path("target.txt")
8484

8585

86-
def test_copy_symlink_templated_target(tmp_path_factory):
86+
def test_copy_symlink_templated_target(
87+
tmp_path_factory: pytest.TempPathFactory,
88+
) -> None:
8789
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
8890
# Prepare repo bundle
8991
repo = src / "repo"
@@ -125,7 +127,7 @@ def test_copy_symlink_templated_target(tmp_path_factory):
125127
assert readlink(dst / "symlink2.txt") == Path("{{ target_name }}.txt")
126128

127129

128-
def test_copy_symlink_missing_target(tmp_path_factory):
130+
def test_copy_symlink_missing_target(tmp_path_factory: pytest.TempPathFactory) -> None:
129131
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
130132
# Prepare repo bundle
131133
repo = src / "repo"
@@ -160,7 +162,9 @@ def test_copy_symlink_missing_target(tmp_path_factory):
160162
) # exists follows symlinks, It returns False as the target doesn't exist
161163

162164

163-
def test_option_preserve_symlinks_false(tmp_path_factory):
165+
def test_option_preserve_symlinks_false(
166+
tmp_path_factory: pytest.TempPathFactory,
167+
) -> None:
164168
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
165169
# Prepare repo bundle
166170
repo = src / "repo"
@@ -194,7 +198,9 @@ def test_option_preserve_symlinks_false(tmp_path_factory):
194198
assert not os.path.islink(dst / "symlink.txt")
195199

196200

197-
def test_option_preserve_symlinks_default(tmp_path_factory):
201+
def test_option_preserve_symlinks_default(
202+
tmp_path_factory: pytest.TempPathFactory,
203+
) -> None:
198204
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
199205
# Prepare repo bundle
200206
repo = src / "repo"
@@ -227,7 +233,7 @@ def test_option_preserve_symlinks_default(tmp_path_factory):
227233
assert not os.path.islink(dst / "symlink.txt")
228234

229235

230-
def test_update_symlink(tmp_path_factory):
236+
def test_update_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
231237
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
232238

233239
build_file_tree(
@@ -287,7 +293,7 @@ def test_update_symlink(tmp_path_factory):
287293
assert readlink(dst / "symlink.txt") == Path("bbbb.txt")
288294

289295

290-
def test_exclude_symlink(tmp_path_factory):
296+
def test_exclude_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
291297
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
292298
# Prepare repo bundle
293299
repo = src / "repo"
@@ -320,7 +326,7 @@ def test_exclude_symlink(tmp_path_factory):
320326
assert not (dst / "symlink.txt").is_symlink()
321327

322328

323-
def test_pretend_symlink(tmp_path_factory):
329+
def test_pretend_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
324330
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
325331
# Prepare repo bundle
326332
repo = src / "repo"
@@ -353,7 +359,7 @@ def test_pretend_symlink(tmp_path_factory):
353359
assert not (dst / "symlink.txt").is_symlink()
354360

355361

356-
def test_copy_symlink_none_path(tmp_path_factory):
362+
def test_copy_symlink_none_path(tmp_path_factory: pytest.TempPathFactory) -> None:
357363
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
358364
# Prepare repo bundle
359365
repo = src / "repo"
@@ -388,7 +394,7 @@ def test_copy_symlink_none_path(tmp_path_factory):
388394
assert not os.path.islink(dst / "symlink.txt")
389395

390396

391-
def test_recursive_symlink(tmp_path_factory: pytest.TempPathFactory):
397+
def test_recursive_symlink(tmp_path_factory: pytest.TempPathFactory) -> None:
392398
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
393399
build_file_tree(
394400
{

tests/test_tmpdir.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def template_path(tmp_path_factory: pytest.TempPathFactory) -> str:
3434
return str(root)
3535

3636

37-
def empty_dir(dir: Path):
37+
def empty_dir(dir: Path) -> None:
3838
assert dir.is_dir()
3939
assert dir.exists()
4040
assert len(list(dir.iterdir())) == 0

tests/test_vcs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_update_using_local_source_path_with_tilde(tmp_path: Path) -> None:
164164
assert worker.answers.combined["_src_path"] == user_src_path
165165

166166

167-
def test_invalid_version(tmp_path):
167+
def test_invalid_version(tmp_path: Path) -> None:
168168
sample = tmp_path / "sample.txt"
169169
with local.cwd(tmp_path):
170170
git("init")

0 commit comments

Comments
 (0)