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

Add __repr__ methods #1115

Merged
merged 2 commits into from
Oct 3, 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
10 changes: 8 additions & 2 deletions src/dipdup/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def __init__(
self._handlers: dict[tuple[str, str], HandlerConfig] = {}
self._hooks: dict[str, HookConfig] = {}

def __str__(self) -> str:
return pformat(self.__dict__)
fabrobles92 marked this conversation as resolved.
Show resolved Hide resolved
def __repr__(self) -> str:
return f'<{self.__class__.__name__}(package={self.package}, transactions={self.transactions})>'

# TODO: The next four properties are process-global. Document later.
@property
Expand Down Expand Up @@ -745,6 +745,9 @@ def __init__(
)
self.logger = logger
self.hook_config = hook_config

def __repr__(self) -> str:
return f'<{self.__class__.__name__}(hook_name={self.hook_config.name})>'

@classmethod
def _wrap(
Expand Down Expand Up @@ -809,6 +812,9 @@ def __init__(
handler_config.parent.name if handler_config.parent else 'unknown',
handler_config.parent._template_values if handler_config.parent else {},
)

def __repr__(self) -> str:
return f'<{self.__class__.__name__}>(<{self.template_values._index}.{self.handler_config.name}>)'

@classmethod
def _wrap(
Expand Down
6 changes: 6 additions & 0 deletions src/dipdup/dipdup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def __init__(self, ctx: DipDupContext) -> None:
self._previous_levels: defaultdict[str, int] = defaultdict(int)
self._last_levels_nonempty: int = 0
self._last_objects_indexed: int = 0

def __repr__(self) -> str:
return f'<{self.__class__.__name__}(indexes={self._indexes}, entrypoint_filter={self._entrypoint_filter}, address_filter={self._address_filter}, code_hash_filter={self._code_hash_filter})>'

async def run(
self,
Expand Down Expand Up @@ -612,6 +615,9 @@ def __init__(self, config: DipDupConfig) -> None:
)
self._index_dispatcher: IndexDispatcher = IndexDispatcher(self._ctx)
self._schema: Schema | None = None

def __repr__(self) -> str:
return f'<{self.__class__.__name__}(package_name={self._ctx.package.name}>'

@property
def schema(self) -> Schema:
Expand Down
3 changes: 3 additions & 0 deletions src/dipdup/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(

self._logger = FormattedLogger(__name__, fmt=f'{config.name}: ' + '{}')
self._state: models.Index | None = None

def __repr__(self) -> str:
return f'<{self.__class__.__name__}(index_name={self._state.name})>'

@property
def queue(self) -> deque[IndexQueueItemT]:
Expand Down
1 change: 1 addition & 0 deletions src/dipdup/indexes/starknet_events/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(
) -> None:
super().__init__(ctx, config, datasources)
self._event_identifiers: dict[str, dict[str, str]] | None = None


@property
def event_identifiers(self) -> dict[str, dict[str, str]]:
Expand Down
7 changes: 7 additions & 0 deletions src/dipdup/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ class Model(TortoiseModel):
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
self._original_versioned_data = self.versioned_data

def __repr__(self) -> str:
pk = getattr(self, 'pk', None)
versioned_data_str = ', '.join(f'{key}={value}' for key, value in self.versioned_data.items())
return f'<{self.__class__.__name__}(pk={pk}, versioned_data=({versioned_data_str}))>'

@classmethod
def _init_from_db(cls, **kwargs: Any) -> Model:
Expand Down Expand Up @@ -536,6 +541,7 @@ def __init_subclass__(cls) -> None:
cls._misses = 0
cls._cache = LRU(cls._maxsize)
super().__init_subclass__()


@classmethod
def clear(cls) -> None:
Expand Down Expand Up @@ -696,6 +702,7 @@ class ContractMetadata(Model):
class Meta:
table = 'dipdup_contract_metadata'
unique_together = ('network', 'contract')



class TokenMetadata(Model):
Expand Down
3 changes: 3 additions & 0 deletions src/dipdup/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def __init__(self, root: Path, quiet: bool = False) -> None:
self._types: dict[str, type[BaseModel]] = {}
self._evm_abis = EvmAbiManager(self)
self._cairo_abis = CairoAbiManager(self)

def __repr__(self) -> str:
return f'<{self.__class__.__name__} (root={self.root})>'

@property
def cairo_abi_paths(self) -> Generator[Any, None, None]:
Expand Down
1 change: 1 addition & 0 deletions src/dipdup/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
self._immune_tables = immune_tables or set()
self._transaction: dipdup.models.VersionedTransaction | None = None
self._pending_updates: deque[dipdup.models.ModelUpdate] = deque()


@asynccontextmanager
async def register(self) -> AsyncIterator[None]:
Expand Down