-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: cleanup unneeded references to typing module #63
Changes from all commits
e33a23f
37a2e56
6d685ea
8584a85
e9b79a4
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 |
---|---|---|
|
@@ -15,9 +15,9 @@ | |
import logging | ||
import time | ||
import uuid | ||
from collections.abc import Sequence | ||
from contextvars import ContextVar | ||
from datetime import datetime | ||
from typing import Union, Optional, List | ||
|
||
from .utils import to_iso | ||
|
||
|
@@ -28,21 +28,18 @@ | |
|
||
def set_corr_id_context_var( | ||
originator: str, | ||
key: Optional[uuid.UUID] = None, | ||
issue_dt: Optional[Union[str, datetime]] = None | ||
key: uuid.UUID = uuid.uuid4(), | ||
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. uuid4() is new to me, I'm guessing that is what we should be using everywhere, I'll try to remember this. 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. I just copied code from inside this function, which I think was using There are other versions of the UUID standard, such as version 1 which uses the current time and the MAC address of the computer to generate a probably unique ID, but I've only ever used v4. https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random) |
||
issue_dt: str | datetime | None = None | ||
) -> None: | ||
""" | ||
Build and set correlation ID ContextVar for logging module, based on originator and | ||
key (or generated UUID). Include issue_dt in correlation ID if provided. | ||
|
||
Args: | ||
originator (str): Function, class, service name, etc. that is using logging module | ||
key (Optional[uuid.UUID]): a UUID. Default: randomly generated UUID. | ||
issue_dt (Optional[Union[str, datetime]]): Datetime when a relevant forecast was issued | ||
key (uuid.UUID, optional): a UUID. Default: randomly generated UUID. | ||
issue_dt (str | datetime | None, optional): Datetime when a relevant forecast was issued | ||
""" | ||
if not key: | ||
key = uuid.uuid4() | ||
|
||
if issue_dt: | ||
if not isinstance(issue_dt, str): | ||
issue_dt = to_iso(issue_dt) | ||
|
@@ -56,7 +53,7 @@ def get_corr_id_context_var_str() -> str: | |
return corr_id_context_var.get() | ||
|
||
|
||
def get_corr_id_context_var_parts() -> List[str]: | ||
def get_corr_id_context_var_parts() -> Sequence[str]: | ||
"""Split correlation ID ContextVar into its parts, such as [originator, key, issue_datetime]""" | ||
return corr_id_context_var.get().split(';') | ||
|
||
|
@@ -159,7 +156,8 @@ def get_default_log_config(level: str, | |
'loggers': { | ||
'': { | ||
'level': level, | ||
'handlers': ['default', 'rabbit'] | ||
# 'handlers': ['default', 'rabbit'] | ||
'handlers': ['default'] | ||
}, | ||
} | ||
} |
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 normally use Sequence but Iterable is likely more correct.
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 thought I read somewhere that Iterable was preferred for arguments because it gives the most flexibility to the caller, whereas Sequence was preferred for return values because it's more specific, and you (hopefully) know what exactly you're returning.
In general I too prefer Sequence.