Skip to content

Commit

Permalink
fix: type not subscriptable (#297)
Browse files Browse the repository at this point in the history
* fix: weird subclassing issue from dep conflict

* chore: `black .`

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BobTheBuidler and github-actions[bot] authored Nov 22, 2024
1 parent 9a7715a commit 5684f87
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
52 changes: 26 additions & 26 deletions dank_mids/semaphores.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import functools
from decimal import Decimal
from typing import TYPE_CHECKING, Literal, Optional, Union
from typing import TYPE_CHECKING, Literal, Optional, Type, Union

import a_sync
from a_sync.primitives import DummySemaphore, ThreadsafeSemaphore
from a_sync.primitives.locks.prio_semaphore import (
_AbstractPrioritySemaphore,
_PrioritySemaphoreContextManager,
)
from eth_typing import HexStr
from web3.types import RPCEndpoint

if TYPE_CHECKING:
Expand Down Expand Up @@ -36,7 +37,12 @@ def __init__(
super().__init__(parent, priority, name)


class BlockSemaphore(_AbstractPrioritySemaphore[str, _BlockSemaphoreContextManager]): # type: ignore [type-var]
_TOP_PRIORITY = -1


# NOTE: keep this so we can include in type stubs
# class BlockSemaphore(_AbstractPrioritySemaphore[str, _BlockSemaphoreContextManager]): # type: ignore [type-var]
class BlockSemaphore(_AbstractPrioritySemaphore):
"""A semaphore for managing concurrency based on block numbers.
This class extends :class:`_AbstractPrioritySemaphore` to provide block-specific concurrency control.
Expand All @@ -49,34 +55,28 @@ class BlockSemaphore(_AbstractPrioritySemaphore[str, _BlockSemaphoreContextManag
:class:`_BlockSemaphoreContextManager`: The context manager used by this semaphore.
"""

_context_manager_class = _BlockSemaphoreContextManager # type: ignore [assignment]
_context_manager_class: Type[_BlockSemaphoreContextManager]
"""The context manager class used by this semaphore."""

_top_priority: int = -1 # type: ignore [assignment]
_top_priority: Literal[-1]
"""The highest priority value, set to -1."""

def __getitem__(self, block: Union[int, str, Literal["latest", None]]) -> "_BlockSemaphoreContextManager": # type: ignore [override]
return super().__getitem__( # type: ignore [return-value]
block
if isinstance(block, int) # type: ignore [index]
else (
int(block.hex(), 16)
if isinstance(block, bytes) # type: ignore [union-attr]
else (
int(block, 16)
if isinstance(block, str) and "0x" in block
else (
block
if block
not in [
None,
"latest",
] # NOTE: We do this to generate an err if an unsuitable value was provided
else self._top_priority
)
)
)
) # type: ignore [index]
def __init__(self, value=1, *, name=None):
super().__init__(_BlockSemaphoreContextManager, -1, value, name=name)

def __getitem__(self, block: Union[int, HexStr, Literal["latest", None]]) -> "_BlockSemaphoreContextManager": # type: ignore [override]
if isinstance(block, int):
priority = block
elif isinstance(block, bytes):
priority = int(block.hex(), 16)
elif isinstance(block, str) and "0x" in block:
priority = int(block, 16)
elif block not in [None, "latest"]:
# NOTE: We do this to generate an err if an unsuitable value was provided
priority = block
else:
priority = _TOP_PRIORITY
return super().__getitem__(priority)


class _MethodSemaphores:
Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ python = ">=3.8,<3.13"
aiofiles = "*"
eth-retry = ">=0.1.15,<0.2"
evmspec = ">=0.0.1,<0.1"
ez-a-sync = ">=0.20.7,<0.25"
ez-a-sync = ">=0.24.7,<1"
multicall = ">=0.6.2,<1"
typed-envs = ">=0.0.2,<0.1"
typed-envs = ">=0.0.5,<0.1"
web3 = ">=5.27,!=5.29.*,!=5.30.*,!=5.31.1,!=5.31.2,<8"

[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 5684f87

Please sign in to comment.