Skip to content

Commit

Permalink
log compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck committed Sep 27, 2023
1 parent 96893f4 commit 1fdc9a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions serializable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

from .formatters import BaseNameFormatter, CurrentFormatter
from .helpers import BaseHelper
from .logging import LOGGER
from .logging import LOGGER, _warning_kwargs

# !! version is managed by semantic_release
# do not use typing here, or else `semantic_release` might have issues finding the variable
Expand Down Expand Up @@ -240,9 +240,9 @@ def _from_json(cls: Type[_T], data: Dict[str, Any]) -> object:
klass_properties = ObjectMetadataLibrary.klass_property_mappings.get(klass_qualified_name, {})

if klass is None:
LOGGER.warning( # type:ignore[call-arg]
LOGGER.warning(
f'{klass_qualified_name} is not a known serializable class',
stacklevel=2)
)
return None

if len(klass_properties) == 1:
Expand Down Expand Up @@ -450,7 +450,7 @@ def _from_xml(cls: Type[_T], data: Union[TextIOWrapper, Element],
if klass is None:
LOGGER.waqqrning( # type:ignore[call-arg]
f'{cls.__module__}.{cls.__qualname__} is not a known serializable class',
stacklevel=2)
**_warning_kwargs)
return None

klass_properties = ObjectMetadataLibrary.klass_property_mappings.get(f'{cls.__module__}.{cls.__qualname__}', {})
Expand Down
6 changes: 3 additions & 3 deletions serializable/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from datetime import date, datetime
from typing import Any

from .logging import LOGGER
from .logging import LOGGER, _warning_kwargs


class BaseHelper(ABC):
Expand Down Expand Up @@ -78,12 +78,12 @@ def deserialize(cls, o: object) -> date:
o = str(o)[:-1]
LOGGER.warning( # type:ignore[call-arg]
'Potential data loss will occur: dates with timezones not supported in Python',
stacklevel=2)
**_warning_kwargs)
if '+' in str(o):
o = str(o)[:str(o).index('+')]
LOGGER.warning( # type:ignore[call-arg]
'Potential data loss will occur: dates with timezones not supported in Python',
stacklevel=2)
**_warning_kwargs)
return date.fromisoformat(str(o))
except ValueError:
raise ValueError(f'Date string supplied ({o}) is not a supported ISO Format')
Expand Down
4 changes: 4 additions & 0 deletions serializable/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
# Copyright (c) Paul Horton. All Rights Reserved.

import logging
from sys import version_info

LOGGER = logging.getLogger(f'{__name__}.LOGGER')
LOGGER.setLevel(logging.DEBUG)

# logger.warning() got additional kwarg since py38
_warning_kwargs = {'stacklevel': 2} if version_info >= (3, 8) else {}

0 comments on commit 1fdc9a6

Please sign in to comment.