Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit cffbd97

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #46 from staticdev/mypy-errors
Fix mypy errors
2 parents e4c8883 + 97f4fc2 commit cffbd97

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ disallow_untyped_decorators = False
2424

2525
[mypy-pytest]
2626
ignore_missing_imports = True
27+
28+
[mypy-inquirer]
29+
ignore_missing_imports = True

src/git_portfolio/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def delete_branches() -> None:
8484
cli.add_command(delete)
8585

8686

87-
def main() -> None:
87+
def main(prog_name: str) -> None:
8888
"""Git Portfolio."""
8989
cli()
9090

src/git_portfolio/config_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def load_configs(self) -> Config:
3838
return Config(**data)
3939
return Config("", "", [])
4040

41-
def save_configs(self, configs: Config):
41+
def save_configs(self, configs: Config) -> None:
4242
"""Write config to YAML file."""
4343
pathlib.Path(self.CONFIG_FOLDER).mkdir(parents=True, exist_ok=True)
4444
configs_dict = vars(configs)

src/git_portfolio/portfolio_manager.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""Command-line interface."""
22
import logging
33
import sys
4+
from typing import Any
5+
from typing import List
46
from typing import Optional
7+
from typing import Set
58
from typing import Union
69

710
import github
@@ -30,7 +33,7 @@ def __init__(self) -> None:
3033
self.config_ini()
3134

3235
def create_issues(
33-
self, issue: Optional[prompt.Issue] = None, github_repo=""
36+
self, issue: Optional[prompt.Issue] = None, github_repo: str = ""
3437
) -> None:
3538
"""Create issues."""
3639
if not issue:
@@ -45,7 +48,9 @@ def create_issues(
4548
for github_repo in self.configs.github_selected_repos:
4649
self._create_issue_from_repo(github_repo, issue, labels)
4750

48-
def _create_issue_from_repo(self, github_repo, issue, labels):
51+
def _create_issue_from_repo(
52+
self, github_repo: str, issue: Any, labels: List[str]
53+
) -> None:
4954
"""Create issue from one repository."""
5055
repo = self.github_connection.get_repo(github_repo)
5156
try:
@@ -63,7 +68,7 @@ def _create_issue_from_repo(self, github_repo, issue, labels):
6368
print(f"{github_repo}: {github_exception.data['message']}.")
6469

6570
def create_pull_requests(
66-
self, pr: Optional[prompt.PullRequest] = None, github_repo=""
71+
self, pr: Optional[prompt.PullRequest] = None, github_repo: str = ""
6772
) -> None:
6873
"""Create pull requests."""
6974
if not pr:
@@ -75,7 +80,7 @@ def create_pull_requests(
7580
for github_repo in self.configs.github_selected_repos:
7681
self._create_pull_request_from_repo(github_repo, pr)
7782

78-
def _create_pull_request_from_repo(self, github_repo, pr):
83+
def _create_pull_request_from_repo(self, github_repo: str, pr: Any) -> None:
7984
"""Create pull request from one repository."""
8085
repo = self.github_connection.get_repo(github_repo)
8186
body = pr.body
@@ -96,12 +101,12 @@ def _create_pull_request_from_repo(self, github_repo, pr):
96101
extra = ""
97102
for error in github_exception.data["errors"]:
98103
if "message" in error:
99-
extra += f"{error['message']} "
104+
extra += f"{error['message']} " # type: ignore
100105
else:
101-
extra += f"Invalid field {error['field']}. "
106+
extra += f"Invalid field {error['field']}. " # type: ignore
102107
print(f"{github_repo}: {github_exception.data['message']}. {extra}")
103108

104-
def _link_issues(self, body, labels, pr, repo):
109+
def _link_issues(self, body: str, labels: Set[Any], pr: Any, repo: Any) -> Any:
105110
"""Return body message linking issues."""
106111
issues = repo.get_issues(state="open")
107112
closes = ""
@@ -117,7 +122,7 @@ def _link_issues(self, body, labels, pr, repo):
117122
return body
118123

119124
def merge_pull_requests(
120-
self, pr_merge: Optional[prompt.PullRequestMerge] = None, github_repo=""
125+
self, pr_merge: Optional[prompt.PullRequestMerge] = None, github_repo: str = ""
121126
) -> None:
122127
"""Merge pull requests."""
123128
if not pr_merge:
@@ -136,7 +141,9 @@ def merge_pull_requests(
136141
for github_repo in self.configs.github_selected_repos:
137142
self._merge_pull_request_from_repo(github_repo, head, pr_merge, state)
138143

139-
def _merge_pull_request_from_repo(self, github_repo, head, pr_merge, state):
144+
def _merge_pull_request_from_repo(
145+
self, github_repo: str, head: str, pr_merge: Any, state: str
146+
) -> None:
140147
"""Merge pull request from one repository."""
141148
repo = self.github_connection.get_repo(github_repo)
142149
pulls = repo.get_pulls(state=state, base=pr_merge.base, head=head)
@@ -165,7 +172,7 @@ def _merge_pull_request_from_repo(self, github_repo, head, pr_merge, state):
165172
)
166173
)
167174

168-
def delete_branches(self, branch="", github_repo="") -> None:
175+
def delete_branches(self, branch: str = "", github_repo: str = "") -> None:
169176
"""Delete branches."""
170177
if not branch:
171178
branch = prompt.delete_branches(self.configs.github_selected_repos)
@@ -176,7 +183,7 @@ def delete_branches(self, branch="", github_repo="") -> None:
176183
for github_repo in self.configs.github_selected_repos:
177184
self._delete_branch_from_repo(github_repo, branch)
178185

179-
def _delete_branch_from_repo(self, github_repo, branch):
186+
def _delete_branch_from_repo(self, github_repo: str, branch: str) -> None:
180187
"""Delete a branch from one repository."""
181188
repo = self.github_connection.get_repo(github_repo)
182189
try:
@@ -216,7 +223,7 @@ def get_github_repos(
216223
user: Union[
217224
github.AuthenticatedUser.AuthenticatedUser, github.NamedUser.NamedUser
218225
],
219-
) -> github.PaginatedList.PaginatedList:
226+
) -> github.PaginatedList.PaginatedList[Any]:
220227
"""Get Github repos from user."""
221228
return user.get_repos()
222229

src/git_portfolio/prompt.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _not_empty_validation(answers: Dict[str, Any], current: str) -> bool:
2929
Issue = collections.namedtuple("Issue", ["title", "body", "labels"])
3030

3131

32-
def create_issues(github_selected_repos):
32+
def create_issues(github_selected_repos: List[str]) -> Issue:
3333
"""Prompt questions to create issues."""
3434
questions = [
3535
inquirer.Text(
@@ -55,7 +55,7 @@ def create_issues(github_selected_repos):
5555
return Issue(answers["title"], answers["body"], answers["labels"])
5656

5757

58-
def delete_branches(github_selected_repos) -> str:
58+
def delete_branches(github_selected_repos: List[str]) -> Any:
5959
"""Prompt questions to delete branches."""
6060
questions = [
6161
inquirer.Text(
@@ -93,7 +93,7 @@ def delete_branches(github_selected_repos) -> str:
9393
)
9494

9595

96-
def create_pull_requests(github_selected_repos) -> PullRequest:
96+
def create_pull_requests(github_selected_repos: List[str]) -> PullRequest:
9797
"""Prompt questions to create pull requests."""
9898
questions = [
9999
inquirer.Text(
@@ -165,7 +165,9 @@ def create_pull_requests(github_selected_repos) -> PullRequest:
165165
)
166166

167167

168-
def merge_pull_requests(github_username, github_selected_repos):
168+
def merge_pull_requests(
169+
github_username: str, github_selected_repos: List[str]
170+
) -> PullRequestMerge:
169171
"""Prompt questions to merge pull requests."""
170172
questions = [
171173
inquirer.Text(
@@ -231,15 +233,15 @@ def connect_github(github_access_token: str) -> ConnectGithub:
231233
return ConnectGithub(answers["github_access_token"], answers["github_hostname"])
232234

233235

234-
def new_repos() -> bool:
236+
def new_repos() -> Any:
235237
"""Prompt question to know if you want to select new repositories."""
236238
answer = inquirer.prompt(
237239
[inquirer.Confirm("", message="Do you want to select new repositories?")]
238240
)[""]
239241
return answer
240242

241243

242-
def select_repos(repo_names) -> List[str]:
244+
def select_repos(repo_names: List[str]) -> Any:
243245
"""Prompt questions to select new repositories."""
244246
while True:
245247
selected = inquirer.prompt(

tests/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ def runner() -> CliRunner:
1313

1414
def test_main_without_argument(runner: CliRunner) -> None:
1515
"""It exits with a status code of one."""
16-
result = runner.invoke(__main__.main, prog_name="gitp")
16+
result = runner.invoke(__main__.main, prog_name="gitp") # type: ignore
1717
assert result.exit_code == 1

0 commit comments

Comments
 (0)