Skip to content

Commit

Permalink
python: Cleanup ListOptions to_dict to use BaeOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-mman committed Jan 14, 2025
1 parent 49a69b0 commit 47b8c63
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions python/svix/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,29 @@ def ensure_tz(x: t.Optional[datetime]) -> t.Optional[datetime]:
return x


def sanitize_field(v: t.Any) -> t.Any:
if isinstance(v, datetime):
return ensure_tz(v)

return v


@dataclass
class ListOptions:
class BaseOptions:
def to_dict(self) -> t.Dict[str, t.Any]:
return {k: sanitize_field(v) for k, v in asdict(self).items() if v is not None}


@dataclass
class ListOptions(BaseOptions):
iterator: t.Optional[str] = None
limit: t.Optional[int] = None

def to_dict(self) -> t.Dict[str, t.Any]:
return {k: v for k, v in asdict(self).items() if v is not None}


@dataclass
class PostOptions:
class PostOptions(BaseOptions):
idempotency_key: t.Optional[str] = None

def to_dict(self) -> t.Dict[str, t.Any]:
return {k: v for k, v in asdict(self).items() if v is not None}


class ApiBase:
_client: AuthenticatedClient
Expand Down

0 comments on commit 47b8c63

Please sign in to comment.