Skip to content

Commit ffdc5ee

Browse files
spoorccben-edna
authored andcommitted
Cleanup import typing
1 parent 44a97a8 commit ffdc5ee

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

dfetch/project/svn.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import os
44
import pathlib
55
import re
6-
from collections import namedtuple
7-
from typing import Dict, List, Optional, Tuple
6+
from typing import Dict, List, NamedTuple, Optional, Tuple
87

98
from dfetch.log import get_logger
109
from dfetch.manifest.version import Version
@@ -20,9 +19,15 @@
2019
logger = get_logger(__name__)
2120

2221

23-
External = namedtuple(
24-
"External", ["name", "toplevel", "path", "revision", "url", "branch", "tag", "src"]
25-
)
22+
class External(NamedTuple):
23+
name: str
24+
toplevel: str
25+
path: str
26+
revision: str
27+
url: str
28+
branch: str
29+
tag: str
30+
src: str
2631

2732

2833
class SvnRepo(VCS):
@@ -46,7 +51,7 @@ def externals() -> List[External]:
4651

4752
repo_root = SvnRepo._get_info_from_target()["Repository Root"]
4853

49-
externals = []
54+
externals: List[External] = []
5055
path_pattern = r"([^\s^-]+)\s+-"
5156
for entry in result.stdout.decode().split(os.linesep * 2):
5257
match: Optional[re.Match[str]] = None

dfetch/vcs/git.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@
44
import re
55
import shutil
66
import tempfile
7-
from collections import namedtuple
87
from pathlib import PurePath
9-
from typing import Dict, Generator, List, Optional, Sequence, Tuple
8+
from typing import Dict, Generator, List, NamedTuple, Optional, Sequence, Tuple
109

1110
from dfetch.log import get_logger
1211
from dfetch.util.cmdline import SubprocessCommandError, run_on_cmdline
1312
from dfetch.util.util import in_directory, safe_rmtree
1413

1514
logger = get_logger(__name__)
1615

17-
Submodule = namedtuple(
18-
"Submodule", ["name", "toplevel", "path", "sha", "url", "branch", "tag"]
19-
)
16+
17+
class Submodule(NamedTuple):
18+
name: str
19+
toplevel: str
20+
path: str
21+
sha: str
22+
url: str
23+
branch: str
24+
tag: str
2025

2126

2227
def get_git_version() -> Tuple[str, str]:
@@ -95,7 +100,7 @@ def _ls_remote(remote: str) -> Dict[str, str]:
95100
logger, f"git ls-remote --heads --tags {remote}"
96101
).stdout.decode()
97102

98-
info = {}
103+
info: Dict[str, str] = {}
99104
for line in filter(lambda x: x, result.split("\n")):
100105
sha, ref = [part.strip() for part in f"{line} ".split("\t", maxsplit=1)]
101106

@@ -338,7 +343,7 @@ def submodules() -> List[Submodule]:
338343
],
339344
)
340345

341-
submodules = []
346+
submodules: List[Submodule] = []
342347
urls: Dict[str, str] = {}
343348
for line in result.stdout.decode().split("\n"):
344349
if line:

0 commit comments

Comments
 (0)