Skip to content

Commit 1bb1293

Browse files
committed
Add type checking
Use type annotations and add mypy as a checker.
1 parent 779e6cb commit 1bb1293

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

passgithelper.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os.path
1616
import subprocess
1717
import sys
18+
from typing import Dict, Optional, Sequence
1819

1920
import xdg.BaseDirectory
2021

@@ -25,7 +26,7 @@
2526
CONFIG_FILE_NAME)
2627

2728

28-
def parse_arguments(argv=None):
29+
def parse_arguments(argv: Optional[Sequence[str]]=None) -> argparse.Namespace:
2930
"""
3031
Parse the command line arguments.
3132
@@ -66,7 +67,7 @@ def parse_arguments(argv=None):
6667
return args
6768

6869

69-
def parse_mapping(mapping_file):
70+
def parse_mapping(mapping_file: Optional[str]) -> configparser.ConfigParser:
7071
"""
7172
Parse the file containing the mappings from hosts to pass entries.
7273
@@ -100,7 +101,7 @@ def parse(mapping_file):
100101
return parse(file_handle)
101102

102103

103-
def parse_request():
104+
def parse_request() -> Dict[str, str]:
104105
"""
105106
Parse the request of the git credential API from stdin.
106107
@@ -123,7 +124,7 @@ def parse_request():
123124
return request
124125

125126

126-
def get_password(request, mapping):
127+
def get_password(request, mapping) -> None:
127128
"""
128129
Resolve the given credential request in the provided mapping definition.
129130
@@ -175,15 +176,15 @@ def decode_skip(line, skip):
175176
sys.exit(1)
176177

177178

178-
def handle_skip():
179+
def handle_skip() -> None:
179180
"""Terminate the process if skipping is requested via an env variable."""
180181
if 'PASS_GIT_HELPER_SKIP' in os.environ:
181182
LOGGER.info(
182183
'Skipping processing as requested via environment variable')
183184
sys.exit(1)
184185

185186

186-
def main(argv=None):
187+
def main(argv: Optional[Sequence[str]]=None) -> None:
187188
"""
188189
Start the pass-git-helper script.
189190

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ import-order-style = google
1818

1919
[coverage:run]
2020
branch = True
21+
22+
[mypy]
23+
ignore_missing_imports=True

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ deps =
2222
flake8-comprehensions
2323
flake8-bugbear
2424
flake8-builtins
25+
mypy
2526
commands =
2627
{envbindir}/python -V
2728
{envbindir}/flake8 {posargs}
29+
{envbindir}/mypy passgithelper.py
2830

2931
[travis]
3032
python =

0 commit comments

Comments
 (0)