Skip to content

Commit

Permalink
Add some docstring and type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Codejune committed Oct 9, 2021
1 parent e68b8d8 commit 861a32a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sdk/core/azure-core/azure/core/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# --------------------------------------------------------------------------
import base64
from json import JSONEncoder
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Union

from .utils._utils import _FixedOffset

if TYPE_CHECKING:
from datetime import timedelta
from datetime import timedelta, date, datetime, time

__all__ = ["NULL", "AzureJSONEncoder"]

Expand Down Expand Up @@ -84,6 +84,8 @@ def _timedelta_as_str(td):


def _datetime_as_isostr(dt):
# type: (Union[datetime, date, time, timedelta]) -> str
"""Converts a datetime.(datetime|date|time|timedelta) object into an ISO 8601 formatted string"""
# First try datetime.datetime
if hasattr(dt, "year") and hasattr(dt, "hour"):
# astimezone() fails for naive times in Python 2.7, so make make sure o is aware (tzinfo is set)
Expand Down Expand Up @@ -118,5 +120,6 @@ def default(self, o): # pylint: disable=too-many-return-statements
try:
return _datetime_as_isostr(o)
except AttributeError:
# This will be raised when it hits value.total_seconds in the method above
pass
return super(AzureJSONEncoder, self).default(o)

0 comments on commit 861a32a

Please sign in to comment.