Skip to content

Commit 2b2e289

Browse files
author
avandras
committed
Fix remaining pyright issues that can be fixed without implementation changes
1 parent bfc8b5a commit 2b2e289

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

patroni/multisite.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from datetime import datetime, timezone
77
from threading import Event, Thread
8-
from typing import Any, Dict, Tuple, Union
8+
from typing import Any, Callable, Dict, Optional, Tuple, TYPE_CHECKING, Union
99

1010
import six
1111

@@ -15,6 +15,9 @@
1515
from .dcs.kubernetes import catch_kubernetes_errors
1616
from .exceptions import DCSError
1717

18+
if TYPE_CHECKING: # pragma: no cover
19+
from .config import Config
20+
1821
logger = logging.getLogger(__name__)
1922

2023

@@ -23,6 +26,8 @@ class AbstractSiteController(object):
2326
# Set whether we are relying on this controller for providing standby config
2427
is_active = False
2528

29+
dcs: AbstractDCS
30+
2631
def start(self):
2732
pass
2833

@@ -71,7 +76,7 @@ def status(self):
7176
class MultisiteController(Thread, AbstractSiteController):
7277
is_active = True
7378

74-
def __init__(self, config: Dict[str, Any], on_change: None = None):
79+
def __init__(self, config: 'Config', on_change: Optional[Callable[..., None]] = None):
7580
super().__init__()
7681
self.stop_requested = False
7782
self.on_change = on_change
@@ -106,7 +111,7 @@ def __init__(self, config: Dict[str, Any], on_change: None = None):
106111
self._dcs_error = None
107112

108113
@staticmethod
109-
def get_dcs_config(config: Dict[str, Any]) -> Tuple[Dict[str, Any], AbstractDCS]:
114+
def get_dcs_config(config: 'Config') -> Tuple[Dict[str, Any], AbstractDCS]:
110115
msconfig = config['multisite']
111116

112117
# Multisite configuration inherits values from main configuration
@@ -327,8 +332,8 @@ def _update_history(self, cluster: Cluster):
327332
self.site_switches = cluster.history.lines[0].get('switches')
328333

329334
if self._has_leader:
330-
if cluster.history and cluster.history.lines and isinstance(cluster.history.lines, dict):
331-
history_state = cluster.history.lines
335+
if cluster.history and cluster.history.lines and isinstance(cluster.history.lines[0], dict):
336+
history_state = cluster.history.lines[0]
332337
if history_state.get('last_leader') != self.name:
333338
new_state = [{'last_leader': self.name, 'switches': history_state.get('switches', 0) + 1}]
334339
self.dcs.set_history_value(json.dumps(new_state))

0 commit comments

Comments
 (0)