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

fix: TxReceipt typings #1991

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ jobs=4
persistent=yes
suggestion-mode=yes
unsafe-load-any-extension=no
load-plugins=plugins.pylint

# Blacklist files or directories (basenames, not paths)
ignore=
Expand Down Expand Up @@ -83,4 +84,4 @@ ignored-classes=
ignored-modules=

# List of members which are set dynamically and missed by pylint inference system
generated-members=ape.reverts
generated-members=ape.reverts,web3.types.TxReceipt.status
12 changes: 5 additions & 7 deletions beamer/agent/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


def _wrap_thread_func(func: Callable) -> Callable:
def wrapper(*args, **kwargs): # type: ignore
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception:
Expand Down Expand Up @@ -464,7 +464,7 @@ def claim_request(request: Request, context: Context) -> None:
context.logger.info(
"Claimed request",
request=request,
txn_hash=receipt.transactionHash.hex(), # type: ignore
txn_hash=receipt.transactionHash.hex(),
)


Expand Down Expand Up @@ -532,7 +532,7 @@ def maybe_challenge(claim: Claim, context: Context) -> bool:
context.logger.info(
"Challenged claim",
claim=claim,
txn_hash=receipt.transactionHash.hex(), # type: ignore
txn_hash=receipt.transactionHash.hex(),
)

return True
Expand Down Expand Up @@ -785,9 +785,7 @@ def _withdraw(claim: Claim, context: Context) -> None:
return

claim.transaction_pending = True
context.logger.info(
"Withdrew", claim=claim.id, txn_hash=receipt.transactionHash.hex() # type: ignore
)
context.logger.info("Withdrew", claim=claim.id, txn_hash=receipt.transactionHash.hex())


def _invalidate(request: Request, claim: Claim, context: Context) -> None:
Expand All @@ -805,5 +803,5 @@ def _invalidate(request: Request, claim: Claim, context: Context) -> None:
request=request.id,
fill_id=claim.fill_id,
claim=claim.id,
txn_hash=receipt.transactionHash.hex(), # type: ignore
txn_hash=receipt.transactionHash.hex(),
)
4 changes: 2 additions & 2 deletions beamer/config/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,5 @@ def write(
log.error("Transaction failed", exc=exc)
sys.exit(1)
else:
txhash = receipt.transactionHash.hex() # type: ignore
log.info("Transaction sent", block=receipt.blockNumber, txhash=txhash) # type: ignore
txhash = receipt.transactionHash.hex()
log.info("Transaction sent", block=receipt.blockNumber, txhash=txhash)
2 changes: 1 addition & 1 deletion beamer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def transact(
else:
break

if receipt.status == 0: # type: ignore
if receipt.status == 0:
raise TransactionFailed("unknown error")
return receipt

Expand Down
29 changes: 29 additions & 0 deletions plugins/mypy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Optional, Callable
from mypy.nodes import Var, SymbolTableNode, MDEF
from mypy.plugin import Plugin, AnalyzeTypeContext


class TxReceiptAttributePlugin(Plugin):

def get_type_analyze_hook(self, fullname: str) -> Optional[Callable]:
def func(ctx: AnalyzeTypeContext) -> None:
symbol_table = ctx.api.lookup_fully_qualified('web3.types.TxReceipt')
names = symbol_table.node.names
type_items = symbol_table.node.typeddict_type.items
for attr_name, attr_type in type_items.items():
if getattr(attr_type, "items", None):
node = Var(attr_name, attr_type)
node.info = attr_type.items[0].type
else:
node = Var(attr_name, attr_type)
node.info = attr_type.type
names[node.name] = SymbolTableNode(MDEF, node)
return symbol_table.node.typeddict_type

if 'TxReceipt' in fullname:
return func
return None


def plugin(version: str) -> Plugin:
return TxReceiptAttributePlugin
20 changes: 20 additions & 0 deletions plugins/pylint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import TYPE_CHECKING

from astroid import MANAGER, Call

if TYPE_CHECKING:
from pylint.lint import PyLinter

print("plugin loaded")

def register(linter: "PyLinter") -> None:
"""This required method auto registers the checker during initialization.

:param linter: The linter to register the checker to.
"""
print('register')

def transform(node):
print('transform ran')

MANAGER.register_transform(Call, transform)
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ warn_unused_ignores = true
strict_equality = true
disallow_untyped_defs = true
explicit_package_bases = true
plugins = "plugins.mypy"

[[tool.mypy.overrides]]
module = ["beamer.tests.*"]
module = ["beamer.*"]
disallow_untyped_defs = false
disable_error_code = "attr-defined,name-defined"

Expand Down
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def func():
print("func ran")

func()