Skip to content

Commit

Permalink
fix: add dict methods to Datapoints
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed May 4, 2024
1 parent 472b9c4 commit c48ba5c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion silverback/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime, timezone
from decimal import Decimal
from enum import Enum # NOTE: `enum.StrEnum` only in Python 3.11+
from typing import Literal
from typing import Iterator, Literal

from ape.logging import get_logger
from pydantic import BaseModel, Field, RootModel, ValidationError, model_validator
Expand Down Expand Up @@ -88,3 +88,19 @@ def parse_datapoints(cls, datapoints: dict) -> dict:
)

return datapoints

# Add dict methods
def get(self, key: str, default: Datapoint | None = None) -> Datapoint | None:
if key in self:
return self[key]

return default

def __iter__(self):
return iter(self.root)

def __getitem__(self, item):
return self.root[item]

def items(self):
return self.root.items()

0 comments on commit c48ba5c

Please sign in to comment.