-
Notifications
You must be signed in to change notification settings - Fork 20
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
mypy: Add type hints to pglookout [BF-1560] #106
base: main
Are you sure you want to change the base?
Changes from 1 commit
0d4ea2c
238eb76
3db5684
2ce13ab
25617d1
016d14d
bf067b3
a462bf9
9b4e13f
45d413b
6ce993e
0d438e9
1f47155
5d4ac6e
51bb85e
e9834d4
a3ad6f8
7434873
30bcd0d
e4e771a
56c01a8
09a15b1
9a0abae
dac0aad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) 2023 Aiven, Helsinki, Finland. https://aiven.io/ | ||
from __future__ import annotations | ||
|
||
from datetime import datetime | ||
from typing import Any, Dict, TypedDict | ||
|
||
|
||
class ReplicationSlotAsDict(TypedDict, total=True): | ||
slot_name: str | ||
plugin: str | ||
slot_type: str | ||
database: str | ||
catalog_xmin: str | ||
restart_lsn: str | ||
confirmed_flush_lsn: str | ||
state_data: str | ||
|
||
|
||
class MemberState(TypedDict, total=False): | ||
"""Represents the state of a member of the cluster. | ||
|
||
Note: | ||
This is a very loose type as no key is mandatory. This is because | ||
it is too dangerous to impose a stricter type until we have a | ||
better test coverage, as it would change some behaviour in the | ||
code (some unconventional behaviour was detected, and it may be a | ||
bug or a feature). | ||
""" | ||
|
||
# Connection Status | ||
connection: bool | ||
fetch_time: str | ||
# Queried Status | ||
db_time: str | datetime | ||
pg_is_in_recovery: bool | ||
pg_last_xact_replay_timestamp: datetime | str | None | ||
pg_last_xlog_receive_location: str | None | ||
pg_last_xlog_replay_location: str | None | ||
# Replication info | ||
replication_slots: list[ReplicationSlotAsDict] | ||
replication_time_lag: float | None | ||
min_replication_time_lag: float | ||
replication_start_time: float | None | ||
|
||
|
||
# Note for future improvements: | ||
# If we want ObserverState to accept arbitrary keys, we have three choices: | ||
# - Use a different type (pydantic, dataclasses, etc.) | ||
# - Use a TypedDict for static keys (connection, fetch_time) and a sub-dict for | ||
# dynamic keys (received from state.json). | ||
# - Wait for something like `allow_extra` to be implemented into TypedDict (unlikely) | ||
# https://github.com/python/mypy/issues/4617 | ||
ObserverState = Dict[str, Any] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually confusing... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I pulled a lot of hair on that one. The names "observer state" were loosely used for different things. Both for an "observed state" and for an "observer state". For now, I'd say to ignore this, as it gets improved in a later commit :-). Ideally, I could also change the name instance variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the naming is not clear enough, I had to jump to a different commit and file just to read the docstring in order to know what was going on in 9b4e13f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm... even with the docstring? I personally think that your name suggestion is also good and I think it makes sense. I'm just wondering.