Skip to content

Commit c10ee29

Browse files
committed
Fix type annotations
This fixes annotations and reworks the argument parser to resolve type errors.
1 parent 2a6c1ae commit c10ee29

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

solc_select/__main__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
def solc_select() -> None:
3030
parser = argparse.ArgumentParser()
3131
subparsers = parser.add_subparsers(
32-
help="Allows users to install and quickly switch between Solidity compiler versions"
32+
help="Allows users to install and quickly switch between Solidity compiler versions",
33+
dest="command",
3334
)
3435
parser_install = subparsers.add_parser(
3536
"install", help="list and install available solc versions"
@@ -51,22 +52,22 @@ def solc_select() -> None:
5152
parser_use = subparsers.add_parser("upgrade", help="upgrades solc-select")
5253
parser_use.add_argument(UPGRADE, nargs="*", help=argparse.SUPPRESS)
5354

54-
args = vars(parser.parse_args())
55+
args = parser.parse_args()
5556

56-
if args.get(INSTALL_VERSIONS) is not None:
57-
versions = args.get(INSTALL_VERSIONS)
57+
if args.command == "install":
58+
versions = args.INSTALL_VERSIONS
5859
if not versions:
5960
print("Available versions to install:")
6061
for version in get_installable_versions():
6162
print(version)
6263
else:
63-
status = install_artifacts(args.get(INSTALL_VERSIONS))
64+
status = install_artifacts(versions)
6465
sys.exit(0 if status else 1)
6566

66-
elif args.get(USE_VERSION) is not None:
67-
switch_global_version(args.get(USE_VERSION), args.get("always_install"), silent=False)
67+
elif args.command == "use":
68+
switch_global_version(args.USE_VERSION, args.always_install, silent=False)
6869

69-
elif args.get(SHOW_VERSIONS) is not None:
70+
elif args.command == "versions":
7071
versions_installed = installed_versions()
7172
if versions_installed:
7273
(current_ver, source) = (None, None)
@@ -86,7 +87,7 @@ def solc_select() -> None:
8687
print(
8788
"No solc version installed. Run `solc-select install --help` for more information"
8889
)
89-
elif args.get(UPGRADE) is not None:
90+
elif args.command == "upgrade":
9091
upgrade_architecture()
9192
else:
9293
parser.parse_args(["--help"])

solc_select/solc_select.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
import urllib.request
1212
from pathlib import Path
13+
from typing import Dict, List, Tuple
1314
from zipfile import ZipFile
1415

1516
from Crypto.Hash import keccak
@@ -61,7 +62,7 @@ def check_emulation_available() -> bool:
6162
return False
6263

6364

64-
def get_emulation_prefix() -> list:
65+
def get_emulation_prefix() -> List[str]:
6566
"""Get the command prefix for emulation if needed."""
6667
if get_arch() != "arm64":
6768
return []
@@ -159,7 +160,7 @@ def upgrade_architecture() -> None:
159160
raise argparse.ArgumentTypeError("Run `solc-select install --help` for more information")
160161

161162

162-
def current_version() -> (str, str):
163+
def current_version() -> Tuple[str, str]:
163164
source = "SOLC_VERSION"
164165
version = os.environ.get(source)
165166
if not version:
@@ -182,7 +183,7 @@ def current_version() -> (str, str):
182183
return version, source
183184

184185

185-
def installed_versions() -> [str]:
186+
def installed_versions() -> List[str]:
186187
return [
187188
f.replace("solc-", "") for f in sorted(os.listdir(ARTIFACTS_DIR)) if f.startswith("solc-")
188189
]
@@ -192,7 +193,7 @@ def artifact_path(version: str) -> Path:
192193
return ARTIFACTS_DIR.joinpath(f"solc-{version}", f"solc-{version}")
193194

194195

195-
def install_artifacts(versions: [str], silent: bool = False) -> bool:
196+
def install_artifacts(versions: List[str], silent: bool = False) -> bool:
196197
# Warn ARM64 users about compatibility on first install
197198
if get_arch() == "arm64" and not silent:
198199
warn_about_arm64()
@@ -274,7 +275,7 @@ def verify_checksum(version: str) -> None:
274275
)
275276

276277

277-
def get_soliditylang_checksums(version: str) -> (str, str):
278+
def get_soliditylang_checksums(version: str) -> Tuple[str, str]:
278279
(_, list_url) = get_url(version=version)
279280
# pylint: disable=consider-using-with
280281
list_json = urllib.request.urlopen(list_url).read()
@@ -289,7 +290,7 @@ def get_soliditylang_checksums(version: str) -> (str, str):
289290
return matches[0]["sha256"], matches[0]["keccak256"]
290291

291292

292-
def get_url(version: str = "", artifact: str = "") -> (str, str):
293+
def get_url(version: str = "", artifact: str = "") -> Tuple[str, str]:
293294
if soliditylang_platform() == LINUX_AMD64:
294295
if version != "" and is_older_linux(version):
295296
return (
@@ -353,14 +354,14 @@ def valid_install_arg(arg: str) -> str:
353354
return valid_version(arg)
354355

355356

356-
def get_installable_versions() -> [str]:
357+
def get_installable_versions() -> List[str]:
357358
installable = list(set(get_available_versions()) - set(installed_versions()))
358359
installable.sort(key=Version)
359360
return installable
360361

361362

362363
# pylint: disable=consider-using-with
363-
def get_available_versions() -> [str]:
364+
def get_available_versions() -> Dict[str, str]:
364365
(_, list_url) = get_url()
365366
list_json = urllib.request.urlopen(list_url).read()
366367
available_releases = json.loads(list_json)["releases"]

solc_select/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from packaging.version import Version
88

99

10-
def mac_binary_is_universal(path: Path):
10+
def mac_binary_is_universal(path: Path) -> bool:
1111
"""Check if the Mac binary is Universal or not. Will throw an exception if run on non-macOS."""
1212
assert sys.platform == "darwin"
1313
result = subprocess.run(["/usr/bin/file", str(path)], capture_output=True, check=False)

0 commit comments

Comments
 (0)