Skip to content

Commit

Permalink
chore: use sequence more
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 14, 2023
1 parent 7f0d594 commit 6b8062c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
18 changes: 9 additions & 9 deletions src/ape/api/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ def settings(self) -> PluginConfig:
return CustomConfig.model_validate(data)

@abstractmethod
def get_versions(self, all_paths: List[Path]) -> Set[str]:
def get_versions(self, all_paths: Sequence[Path]) -> Set[str]:
"""
Retrieve the set of available compiler versions for this plugin to compile ``all_paths``.
Args:
all_paths (List[pathlib.Path]): The list of paths.
all_paths (Sequence[pathlib.Path]): The list of paths.
Returns:
Set[str]: A set of available compiler versions.
"""

@raises_not_implemented
def get_compiler_settings( # type: ignore[empty-body]
self, contract_filepaths: List[Path], base_path: Optional[Path] = None
self, contract_filepaths: Sequence[Path], base_path: Optional[Path] = None
) -> Dict[Version, Dict]:
"""
Get a mapping of the settings that would be used to compile each of the sources
by the compiler version number.
Args:
contract_filepaths (List[pathlib.Path]): The list of paths.
contract_filepaths (Sequence[pathlib.Path]): The list of paths.
base_path (Optional[pathlib.Path]): The contracts folder base path.
Returns:
Expand All @@ -83,13 +83,13 @@ def get_compiler_settings( # type: ignore[empty-body]

@abstractmethod
def compile(
self, contract_filepaths: List[Path], base_path: Optional[Path]
self, contract_filepaths: Sequence[Path], base_path: Optional[Path]
) -> List[ContractType]:
"""
Compile the given source files. All compiler plugins must implement this function.
Args:
contract_filepaths (List[pathlib.Path]): A list of source file paths to compile.
contract_filepaths (Sequence[pathlib.Path]): A list of source file paths to compile.
base_path (Optional[pathlib.Path]): Optionally provide the base path, such as the
project ``contracts/`` directory. Defaults to ``None``. When using in a project
via ``ape compile``, gets set to the project's ``contracts/`` directory.
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_imports( # type: ignore[empty-body]
compiler.
Args:
contract_filepaths (List[pathlib.Path]): A list of source file paths to compile.
contract_filepaths (Sequence[pathlib.Path]): A list of source file paths to compile.
base_path (Optional[pathlib.Path]): Optionally provide the base path, such as the
project ``contracts/`` directory. Defaults to ``None``. When using in a project
via ``ape compile``, gets set to the project's ``contracts/`` directory.
Expand All @@ -141,14 +141,14 @@ def get_imports( # type: ignore[empty-body]
@raises_not_implemented
def get_version_map( # type: ignore[empty-body]
self,
contract_filepaths: List[Path],
contract_filepaths: Sequence[Path],
base_path: Optional[Path] = None,
) -> Dict[Version, Set[Path]]:
"""
Get a map of versions to source paths.
Args:
contract_filepaths (List[Path]): Input source paths. Defaults to all source paths
contract_filepaths (Sequence[Path]): Input source paths. Defaults to all source paths
per compiler.
base_path (Path): The base path of sources. Defaults to the project's
``contracts_folder``.
Expand Down
5 changes: 3 additions & 2 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Iterator,
List,
Optional,
Sequence,
Tuple,
Type,
Union,
Expand Down Expand Up @@ -362,12 +363,12 @@ def encode_transaction(
"""

@abstractmethod
def decode_logs(self, logs: List[Dict], *events: EventABI) -> Iterator["ContractLog"]:
def decode_logs(self, logs: Sequence[Dict], *events: EventABI) -> Iterator["ContractLog"]:
"""
Decode any contract logs that match the given event ABI from the raw log data.
Args:
logs (List[Dict]): A list of raw log data from the chain.
logs (Sequence[Dict]): A list of raw log data from the chain.
*events (EventABI): Event definitions to decode.
Returns:
Expand Down
4 changes: 2 additions & 2 deletions src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def manifest(self) -> PackageManifest:

@abstractmethod
def create_manifest(
self, file_paths: Optional[List[Path]] = None, use_cache: bool = True
self, file_paths: Optional[Sequence[Path]] = None, use_cache: bool = True
) -> PackageManifest:
"""
Create a manifest from the project.
Args:
file_paths (Optional[List[Path]]): An optional list of paths to compile
file_paths (Optional[Sequence[Path]]): An optional list of paths to compile
from this project.
use_cache (bool): Set to ``False`` to clear caches and force a re-compile.
Expand Down
4 changes: 2 additions & 2 deletions src/ape/managers/project/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Sequence

from ethpm_types import ContractType, PackageManifest, Source
from ethpm_types.utils import compute_checksum
Expand Down Expand Up @@ -160,7 +160,7 @@ def process_config_file(self, **kwargs) -> bool:
return True

def create_manifest(
self, file_paths: Optional[List[Path]] = None, use_cache: bool = True
self, file_paths: Optional[Sequence[Path]] = None, use_cache: bool = True
) -> PackageManifest:
# Read the project config and migrate project-settings to Ape settings if needed.
compile_config = self.config_manager.get_config("compile")
Expand Down
4 changes: 2 additions & 2 deletions src/ape_ethereum/ecosystem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from copy import deepcopy
from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union, cast
from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple, Type, Union, cast

from eth_abi import decode, encode
from eth_abi.exceptions import InsufficientDataBytes, NonEmptyPaddingBytes
Expand Down Expand Up @@ -669,7 +669,7 @@ def create_transaction(self, **kwargs) -> TransactionAPI:

return txn_class(**kwargs)

def decode_logs(self, logs: List[Dict], *events: EventABI) -> Iterator["ContractLog"]:
def decode_logs(self, logs: Sequence[Dict], *events: EventABI) -> Iterator["ContractLog"]:
if not logs:
return

Expand Down
6 changes: 3 additions & 3 deletions src/ape_pm/compiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from pathlib import Path
from typing import List, Optional, Set
from typing import List, Optional, Sequence, Set

from eth_pydantic_types import HexBytes
from eth_utils import is_0x_prefixed
Expand All @@ -17,13 +17,13 @@ class InterfaceCompiler(CompilerAPI):
def name(self) -> str:
return "ethpm"

def get_versions(self, all_paths: List[Path]) -> Set[str]:
def get_versions(self, all_paths: Sequence[Path]) -> Set[str]:
# NOTE: This bypasses the serialization of this compiler into the package manifest's
# ``compilers`` field. You should not do this with a real compiler plugin.
return set()

def compile(
self, filepaths: List[Path], base_path: Optional[Path] = None
self, filepaths: Sequence[Path], base_path: Optional[Path] = None
) -> List[ContractType]:
filepaths.sort() # Sort to assist in reproducing consistent results.
contract_types: List[ContractType] = []
Expand Down

0 comments on commit 6b8062c

Please sign in to comment.