Skip to content

Commit 997c901

Browse files
committed
Modernize types to Python 3.10+ style
1 parent 334ff91 commit 997c901

File tree

15 files changed

+44
-55
lines changed

15 files changed

+44
-55
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ solc-select = "solc_select.__main__:solc_select"
6161
solc = "solc_select.__main__:solc"
6262

6363
[tool.ruff]
64-
target-version = "py38"
64+
target-version = "py310"
6565
line-length = 100
6666

6767
[tool.ruff.lint]

solc_select/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import sys
3-
from typing import List
43

54
from .constants import (
65
INSTALL_COMMAND,
@@ -23,7 +22,7 @@
2322
from .utils import sort_versions
2423

2524

26-
def solc_select_install(service: SolcService, versions: List[str]) -> None:
25+
def solc_select_install(service: SolcService, versions: list[str]) -> None:
2726
"""Handle the install command."""
2827
if not versions:
2928
print("Available versions to install:")

solc_select/exceptions.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
and more informative error messages throughout the application.
66
"""
77

8-
from typing import List, Optional
9-
108

119
class SolcSelectError(Exception):
1210
"""Base exception for all solc-select errors."""
@@ -20,8 +18,8 @@ class VersionNotFoundError(SolcSelectError):
2018
def __init__(
2119
self,
2220
version: str,
23-
available_versions: Optional[List[str]] = None,
24-
suggestion: Optional[str] = None,
21+
available_versions: list[str] | None = None,
22+
suggestion: str | None = None,
2523
):
2624
self.version = version
2725
self.available_versions = available_versions or []
@@ -47,8 +45,8 @@ class VersionNotInstalledError(SolcSelectError):
4745
def __init__(
4846
self,
4947
version: str,
50-
installed_versions: Optional[List[str]] = None,
51-
source: Optional[str] = None,
48+
installed_versions: list[str] | None = None,
49+
source: str | None = None,
5250
):
5351
self.version = version
5452
self.installed_versions = installed_versions or []
@@ -73,7 +71,7 @@ def __init__(
7371
class PlatformNotSupportedError(SolcSelectError):
7472
"""Raised when platform is not supported for a specific version."""
7573

76-
def __init__(self, version: str, platform: str, min_version: Optional[str] = None):
74+
def __init__(self, version: str, platform: str, min_version: str | None = None):
7775
self.version = version
7876
self.platform = platform
7977
self.min_version = min_version
@@ -115,7 +113,7 @@ class NetworkError(SolcSelectError):
115113
"""Raised when network operations fail."""
116114

117115
def __init__(
118-
self, operation: str, url: Optional[str] = None, original_error: Optional[Exception] = None
116+
self, operation: str, url: str | None = None, original_error: Exception | None = None
119117
):
120118
self.operation = operation
121119
self.url = url

solc_select/infrastructure/filesystem.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import os
99
import shutil
1010
from pathlib import Path
11-
from typing import Optional
1211

1312
from ..constants import ARTIFACTS_DIR, SOLC_SELECT_DIR
1413
from ..models import SolcVersion
@@ -27,7 +26,7 @@ def _ensure_directories(self) -> None:
2726
self.artifacts_dir.mkdir(parents=True, exist_ok=True)
2827
self.config_dir.mkdir(parents=True, exist_ok=True)
2928

30-
def get_current_version(self) -> Optional[SolcVersion]:
29+
def get_current_version(self) -> SolcVersion | None:
3130
"""Get the currently selected version.
3231
3332
Returns:

solc_select/infrastructure/http_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
retry logic and proper timeout handling.
66
"""
77

8-
from typing import Any, Mapping, Optional, Tuple, Union
8+
from collections.abc import Mapping
9+
from typing import Any
910

1011
import requests
1112
from requests.adapters import HTTPAdapter
@@ -22,10 +23,10 @@ def send(
2223
self,
2324
request: PreparedRequest,
2425
stream: bool = False,
25-
timeout: Union[float, Tuple[float, float], Tuple[float, None], None] = None,
26-
verify: Union[bool, str] = True,
27-
cert: Union[bytes, str, Tuple[Union[bytes, str], Union[bytes, str]], None] = None,
28-
proxies: Optional[Mapping[str, str]] = None,
26+
timeout: float | tuple[float, float] | tuple[float, None] | None = None,
27+
verify: bool | str = True,
28+
cert: bytes | str | tuple[bytes | str, bytes | str] | None = None,
29+
proxies: Mapping[str, str] | None = None,
2930
) -> Response:
3031
timeout = timeout or self.timeout
3132
return super().send(

solc_select/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import sys
1111
from dataclasses import dataclass
1212
from pathlib import Path
13-
from typing import Optional
1413

1514
from packaging.version import Version
1615

@@ -257,7 +256,7 @@ class SolcArtifact:
257256
platform: Platform
258257
download_url: str
259258
checksum_sha256: str
260-
checksum_keccak256: Optional[str]
259+
checksum_keccak256: str | None
261260
file_path: Path
262261

263262
def __post_init__(self) -> None:

solc_select/repositories.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from abc import ABC, abstractmethod
99
from functools import lru_cache
10-
from typing import Any, Dict, List, Optional, Tuple
10+
from typing import Any
1111

1212
import requests
1313
from packaging.version import Version
@@ -44,7 +44,7 @@ def list_url(self) -> str:
4444
pass
4545

4646
@lru_cache(maxsize=5) # noqa: B019
47-
def _fetch_list_json(self) -> Dict[str, Any]:
47+
def _fetch_list_json(self) -> dict[str, Any]:
4848
"""Fetch and cache the list.json data from the repository.
4949
5050
Returns:
@@ -56,7 +56,7 @@ def _fetch_list_json(self) -> Dict[str, Any]:
5656

5757
@property
5858
@lru_cache(maxsize=5) # noqa: B019
59-
def available_versions(self) -> Dict[str, str]:
59+
def available_versions(self) -> dict[str, str]:
6060
"""Get available versions as a dict of version -> artifact_filename."""
6161
list_data = self._fetch_list_json()
6262
all_releases = list_data["releases"]
@@ -77,7 +77,7 @@ def latest_version(self) -> SolcVersion:
7777
version_objs = [SolcVersion.parse(v) for v in versions]
7878
return max(version_objs)
7979

80-
def _filter_versions(self, releases: Dict[str, str]) -> Dict[str, str]:
80+
def _filter_versions(self, releases: dict[str, str]) -> dict[str, str]:
8181
"""Filter versions based on repository-specific criteria.
8282
8383
Override this method to apply custom filtering logic.
@@ -89,7 +89,7 @@ def get_download_url(self, version: SolcVersion, artifact_filename: str) -> str:
8989
"""Get the download URL for a specific version."""
9090
return f"{self.base_url}{artifact_filename}"
9191

92-
def get_checksums(self, version: SolcVersion) -> Tuple[str, Optional[str]]:
92+
def get_checksums(self, version: SolcVersion) -> tuple[str, str | None]:
9393
"""Get SHA256 and optional Keccak256 checksums for a version."""
9494
list_data = self._fetch_list_json()
9595
builds = list_data["builds"]
@@ -191,7 +191,7 @@ def base_url(self) -> str:
191191
def list_url(self) -> str:
192192
return ALLOY_SOLC_JSON
193193

194-
def _filter_versions(self, releases: Dict[str, str]) -> Dict[str, str]:
194+
def _filter_versions(self, releases: dict[str, str]) -> dict[str, str]:
195195
"""Filter to only include versions in the supported ARM64 range."""
196196
min_version = Version(ALLOY_ARM64_MIN_VERSION)
197197
max_version = Version(ALLOY_ARM64_MAX_VERSION)
@@ -219,7 +219,7 @@ class CompositeRepository:
219219

220220
def __init__(self, platform: Platform, session: requests.Session):
221221
self.platform = platform
222-
self.repositories: List[AbstractSolcRepository] = []
222+
self.repositories: list[AbstractSolcRepository] = []
223223

224224
# Always include the main soliditylang repository
225225
self.repositories.append(SoliditylangRepository(platform, session))
@@ -233,7 +233,7 @@ def __init__(self, platform: Platform, session: requests.Session):
233233

234234
@property
235235
@lru_cache(maxsize=5) # noqa: B019
236-
def available_versions(self) -> Dict[str, str]:
236+
def available_versions(self) -> dict[str, str]:
237237
"""Get all available versions from all repositories."""
238238
all_versions = {}
239239

solc_select/services/artifact_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from functools import partial
1212
from io import BufferedRandom
1313
from pathlib import Path
14-
from typing import List
1514
from zipfile import ZipFile
1615

1716
import requests
@@ -33,7 +32,7 @@ def __init__(
3332
self.platform = platform
3433
self.session = session
3534

36-
def get_installed_versions(self) -> List[SolcVersion]:
35+
def get_installed_versions(self) -> list[SolcVersion]:
3736
"""Get list of installed versions.
3837
3938
Returns:
@@ -260,7 +259,7 @@ def _extract_zip_archive(self, artifact: SolcArtifact) -> None:
260259
# Make executable
261260
artifact.file_path.chmod(0o775)
262261

263-
def install_versions(self, versions: List[SolcVersion], silent: bool = False) -> bool:
262+
def install_versions(self, versions: list[SolcVersion], silent: bool = False) -> bool:
264263
"""Install multiple versions concurrently.
265264
266265
Args:

solc_select/services/platform_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import contextlib
99
import sys
1010
from pathlib import Path
11-
from typing import List
1211

1312
from ..constants import SOLC_SELECT_DIR
1413
from ..models import Platform, SolcVersion
@@ -20,7 +19,7 @@ class PlatformService:
2019
def __init__(self, platform: Platform):
2120
self.platform = platform
2221

23-
def get_emulation_prefix(self) -> List[str]:
22+
def get_emulation_prefix(self) -> list[str]:
2423
"""Get the command prefix for emulation if needed.
2524
2625
Returns:

solc_select/services/solc_service.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import subprocess
99
import sys
10-
from typing import List, Optional, Tuple
1110

1211
from ..exceptions import (
1312
ArchitectureUpgradeError,
@@ -29,7 +28,7 @@
2928
class SolcService:
3029
"""Main service facade for solc-select operations."""
3130

32-
def __init__(self, platform: Optional[Platform] = None):
31+
def __init__(self, platform: Platform | None = None):
3332
if platform is None:
3433
platform = Platform.current()
3534

@@ -41,7 +40,7 @@ def __init__(self, platform: Optional[Platform] = None):
4140
self.artifact_manager = ArtifactManager(self.repository, platform, self.session)
4241
self.platform_service = PlatformService(platform)
4342

44-
def get_current_version(self) -> Tuple[Optional[SolcVersion], str]:
43+
def get_current_version(self) -> tuple[SolcVersion | None, str]:
4544
"""Get the current version and its source.
4645
4746
Returns:
@@ -65,16 +64,16 @@ def get_current_version(self) -> Tuple[Optional[SolcVersion], str]:
6564

6665
return version, source
6766

68-
def get_installed_versions(self) -> List[SolcVersion]:
67+
def get_installed_versions(self) -> list[SolcVersion]:
6968
"""Get list of installed versions."""
7069
return self.artifact_manager.get_installed_versions()
7170

72-
def get_installable_versions(self) -> List[SolcVersion]:
71+
def get_installable_versions(self) -> list[SolcVersion]:
7372
"""Get versions that can be installed."""
7473
installed = self.get_installed_versions()
7574
return self.version_manager.get_installable_versions(installed)
7675

77-
def install_versions(self, version_strings: List[str], silent: bool = False) -> bool:
76+
def install_versions(self, version_strings: list[str], silent: bool = False) -> bool:
7877
"""Install one or more versions.
7978
8079
Args:
@@ -180,7 +179,7 @@ def upgrade_architecture(self) -> None:
180179
else:
181180
print("solc-select is already up to date")
182181

183-
def execute_solc(self, args: List[str]) -> None:
182+
def execute_solc(self, args: list[str]) -> None:
184183
"""Execute solc with the current version.
185184
186185
Args:

0 commit comments

Comments
 (0)