Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix sourcery warnings #216

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dank_mids/_debugging/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, chainid: int):
if not isinstance(chainid, int):
raise TypeError(f"`chainid` must be an integer. You passed {chainid}") from None
self.chainid = chainid
self.path = self.path + f"/{self.chainid}"
self.path += f"/{self.chainid}"
self.ensure_dir()
@lru_cache(maxsize=1)
def ensure_dir(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion dank_mids/brownie_patch/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __validate_output(abi: Dict[str, Any], hexstr: BytesLike):
revert_str = f"Panic (error code: {error_code})"
raise Revert(f"Call reverted: {revert_str}")
elif selector == "0xc1b84b2f":
raise Revert(f"Call reverted: execution reverted")
raise Revert("Call reverted: execution reverted")
if abi["outputs"] and not hexstr:
raise Revert("No data was returned - the call likely reverted")
except ValueError as e:
Expand Down
5 changes: 2 additions & 3 deletions dank_mids/brownie_patch/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def __get_method_object__(self, name: str) -> DankContractMethod:
natspec = self._build["natspec"]["methods"].get(sig, {})

if overloaded is False:
fn = _get_method_object(self.address, abi, full_name, self._owner, natspec)
return fn
return _get_method_object(self.address, abi, full_name, self._owner, natspec)

# special logic to handle function overloading
elif overloaded is True:
Expand Down Expand Up @@ -123,6 +122,6 @@ class _ContractMethodPlaceholder:
"""A sentinel object that indicates a Contract does have a member by a specific name."""

def _check_persist(persist: bool) -> Literal[True]:
if persist is False:
if not persist:
raise NotImplementedError("persist: False")
return persist
11 changes: 5 additions & 6 deletions dank_mids/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,23 @@ def set_batch_size_limit(self, new_limit: int) -> None:
@lru_cache(maxsize=1024)
def _select_mcall_target_for_block(self, block) -> "_MulticallContract":
if block == 'latest':
return self.mc3 if self.mc3 else self.mc2 # type: ignore [return-value]
return self.mc3 or self.mc2 # type: ignore [return-value]
if self.mc3 and not self.mc3.needs_override_code_for_block(block):
return self.mc3
if self.mc2:
# We don't care if mc2 needs override code, mc2 override code is shorter
return self.mc2
return self.mc3 # type: ignore [return-value]
# We don't care if mc2 needs override code, mc2 override code is shorter
return self.mc2 or self.mc3 # type: ignore [return-value]

def __setup_attrdict_middleware(self) -> None:
"""This will only run for web3 versions > 6.0. It runs one time when the instance is initialized."""
from web3.middleware import async_attrdict_middleware
from web3.middleware import async_attrdict_middleware # type: ignore [attr-defined]
try:
self.w3.middleware_onion.add(async_attrdict_middleware)
except ValueError as e:
if str(e) != "You can't add the same un-named instance twice":
raise
# NOTE: the web3 instance already has the middleware


class _MulticallContract(Struct):
address: ChecksumAddress
deploy_block: Optional[BlockNumber]
Expand Down
5 changes: 4 additions & 1 deletion dank_mids/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ def decode_result(self, method: Optional[RPCEndpoint] = None, _caller = None) ->
try:
return msgspec.json.decode(self.result, type=typ)
except msgspec.ValidationError as e:
raise ValueError(e, f'method: {method} result: {msgspec.json.decode(self.result)}').with_traceback(e.__traceback__)
raise ValueError(
e,
f'method: {method} result: {msgspec.json.decode(self.result)}',
).with_traceback(e.__traceback__) from e
try:
start = time()
decoded = msgspec.json.decode(self.result, type=typ)
Expand Down
Loading