Skip to content

Commit 1173c79

Browse files
committed
Fix pyright issues
1 parent 1268f63 commit 1173c79

32 files changed

Lines changed: 129 additions & 87 deletions

create_venv.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ def pip_install(context: Any, *args: Any) -> None:
4545
intended for the global Python environment
4646
(same as EnvBuilder's _setup_pip)
4747
"""
48-
subprocess.call( # nosec
48+
subprocess.check_call( # nosec
4949
(context.env_exe, "-Im", "pip", "install") + args,
5050
stderr=subprocess.STDOUT,
51-
check=True,
5251
)
5352

5453

dfetch/commands/check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import argparse
2323
import os
24-
from typing import Any, List # pylint: disable=unused-import
24+
from typing import List
2525

2626
import dfetch.commands.command
2727
import dfetch.manifest.manifest
@@ -46,7 +46,7 @@ class Check(dfetch.commands.command.Command):
4646
"""
4747

4848
@staticmethod
49-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
49+
def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None:
5050
"""Add the parser menu for this action."""
5151
parser = dfetch.commands.command.Command.parser(subparsers, Check)
5252
parser.add_argument(

dfetch/commands/command.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
"""A generic command."""
22

33
import argparse
4+
import sys
45
from abc import ABC, abstractmethod
5-
from typing import Any, Type, TypeVar, cast # pylint: disable=unused-import
6+
from argparse import ArgumentParser # pylint: disable=unused-import
7+
from typing import Type, TypeVar
8+
9+
if sys.version_info > (3, 9):
10+
from typing import TypeAlias
11+
12+
SubparserActionType: TypeAlias = (
13+
"argparse._SubParsersAction[ArgumentParser]" # pyright: ignore[reportPrivateUsage] #pylint: disable=protected-access
14+
)
15+
else:
16+
SubparserActionType = (
17+
argparse._SubParsersAction # pyright: ignore[reportPrivateUsage] #pylint: disable=protected-access
18+
)
619

720

821
class Command(ABC):
@@ -20,7 +33,7 @@ class Command(ABC):
2033

2134
@staticmethod
2235
@abstractmethod
23-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
36+
def create_menu(subparsers: SubparserActionType) -> None:
2437
"""Add a sub-parser to the given parser.
2538
2639
Args:
@@ -42,7 +55,7 @@ def __call__(self, args: argparse.Namespace) -> None:
4255

4356
@staticmethod
4457
def parser(
45-
subparsers: "argparse._SubParsersAction[Any]",
58+
subparsers: SubparserActionType,
4659
command: Type["Command.CHILD_TYPE"],
4760
) -> "argparse.ArgumentParser":
4861
"""Generate the parser.
@@ -72,4 +85,4 @@ def parser(
7285
)
7386

7487
parser.set_defaults(func=command())
75-
return cast(argparse.ArgumentParser, parser)
88+
return parser

dfetch/commands/diff.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
import argparse
5454
import os
55-
from typing import Any # pylint: disable=unused-import
5655
from typing import List
5756

5857
import dfetch.commands.command
@@ -79,7 +78,7 @@ class Diff(dfetch.commands.command.Command):
7978
"""
8079

8180
@staticmethod
82-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
81+
def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None:
8382
"""Add the parser menu for this action."""
8483
parser = dfetch.commands.command.Command.parser(subparsers, Diff)
8584
parser.add_argument(

dfetch/commands/environment.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import argparse
44
import platform
5-
from typing import Any # pylint: disable=unused-import
65

76
import dfetch.commands.command
87
from dfetch.log import get_logger
@@ -18,7 +17,7 @@ class Environment(dfetch.commands.command.Command):
1817
"""
1918

2019
@staticmethod
21-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
20+
def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None:
2221
"""Add the parser menu for this action."""
2322
dfetch.commands.command.Command.parser(subparsers, Environment)
2423

dfetch/commands/freeze.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import argparse
4242
import os
4343
import shutil
44-
from typing import Any # pylint: disable=unused-import
4544
from typing import List
4645

4746
import dfetch.commands.command
@@ -63,7 +62,7 @@ class Freeze(dfetch.commands.command.Command):
6362
"""
6463

6564
@staticmethod
66-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
65+
def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None:
6766
"""Add the parser menu for this action."""
6867
dfetch.commands.command.Command.parser(subparsers, Freeze)
6968

dfetch/commands/import_.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
import os
8585
import re
8686
from itertools import combinations
87-
from typing import Any # pylint: disable=unused-import
8887
from typing import List, Sequence, Set, Tuple
8988

9089
import dfetch.commands.command
@@ -107,7 +106,7 @@ class Import(dfetch.commands.command.Command):
107106
"""
108107

109108
@staticmethod
110-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
109+
def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None:
111110
"""Add the parser menu for this action."""
112111
dfetch.commands.command.Command.parser(subparsers, Import)
113112

@@ -265,7 +264,7 @@ def _determine_best_remotes(projects_urls: Set[str]) -> Tuple[str, ...]:
265264
potential_remotes = potential_remotes - useless_potential
266265

267266
# For each permutation of any length, calculate the solution score
268-
solutions = []
267+
solutions: List[Tuple[int, Tuple[str, ...]]] = []
269268
for i in range(min(len(potential_remotes), max_remotes)):
270269
for solution in combinations(potential_remotes, i):
271270
score = _calculate_solution_score(solution, projects_urls)

dfetch/commands/init.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import argparse
77
import os
88
import shutil
9-
from typing import Any # pylint: disable=unused-import
109

1110
import dfetch.commands.command
1211
from dfetch import DEFAULT_MANIFEST_NAME
@@ -23,7 +22,7 @@ class Init(dfetch.commands.command.Command):
2322
"""
2423

2524
@staticmethod
26-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
25+
def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None:
2726
"""Add the parser menu for this action."""
2827
dfetch.commands.command.Command.parser(subparsers, Init)
2928

dfetch/commands/report.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import argparse
77
import glob
88
import os
9-
from typing import Any # pylint: disable=unused-import
109

1110
import infer_license
1211

@@ -29,7 +28,7 @@ class Report(dfetch.commands.command.Command):
2928
"""
3029

3130
@staticmethod
32-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
31+
def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None:
3332
"""Add the parser menu for this action."""
3433
parser = dfetch.commands.command.Command.parser(subparsers, Report)
3534

dfetch/commands/update.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import argparse
2323
import os
2424
from pathlib import Path
25-
from typing import Any # pylint: disable=unused-import
2625
from typing import List
2726

2827
import dfetch.commands.command
@@ -45,7 +44,7 @@ class Update(dfetch.commands.command.Command):
4544
"""
4645

4746
@staticmethod
48-
def create_menu(subparsers: "argparse._SubParsersAction[Any]") -> None:
47+
def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None:
4948
"""Add the menu for the update action."""
5049
parser = dfetch.commands.command.Command.parser(subparsers, Update)
5150
parser.add_argument(

0 commit comments

Comments
 (0)