Skip to content

Commit

Permalink
added more type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
toluaina committed Sep 25, 2021
1 parent c8b57fb commit 21cd396
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 7 additions & 6 deletions pgsync/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""PGSync Settings."""
import logging
import logging.config
from typing import Optional

from environs import Env

Expand Down Expand Up @@ -98,11 +99,11 @@


# Logging:
def get_logging_config(silent_loggers=None):
def _get_logging_config(silent_loggers: Optional[str] = None):
"""
Return the python logging configuration based on environment variables.
"""
logging_config = {
config: dict = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
Expand Down Expand Up @@ -131,19 +132,19 @@ def get_logging_config(silent_loggers=None):
}
if silent_loggers:
for silent_logger in silent_loggers:
logging_config["loggers"][silent_logger] = {
config["loggers"][silent_logger] = {
"level": "INFO",
}

for logger_config in env.list("CUSTOM_LOGGING", default=[]):
logger, level = logger_config.split("=")
logging_config["loggers"][logger] = {
config["loggers"][logger] = {
"level": level,
}
return logging_config
return config


LOGGING = get_logging_config(
LOGGING = _get_logging_config(
silent_loggers=[
"urllib3.connectionpool",
"urllib3.util.retry",
Expand Down
12 changes: 6 additions & 6 deletions pgsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,17 @@ def _update(
docs: List = []
for payload in payloads:
payload_data: dict = self._payload_data(payload)
primary_values = [
primary_values: List = [
payload_data[key] for key in node.model.primary_keys
]
primary_fields = dict(
primary_fields: dict = dict(
zip(node.model.primary_keys, primary_values)
)
filters[node.table].append(
{key: value for key, value in primary_fields.items()}
)

old_values = []
old_values: List = []
for key in root.model.primary_keys:
if key in payload.get("old").keys():
old_values.append(payload.get("old")[key])
Expand All @@ -434,7 +434,7 @@ def _update(
len(old_values) == len(new_values)
and old_values != new_values
):
doc = {
doc: dict = {
"_id": self.get_doc_id(old_values),
"_index": self.index,
"_op_type": "delete",
Expand All @@ -457,10 +457,10 @@ def _update(

payload_data: dict = self._payload_data(payload)

primary_values = [
primary_values: List = [
payload_data[key] for key in node.model.primary_keys
]
primary_fields = dict(
primary_fields: dict = dict(
zip(node.model.primary_keys, primary_values)
)

Expand Down

0 comments on commit 21cd396

Please sign in to comment.