Skip to content

Commit

Permalink
Add warnings for .get() parsing changes in 0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
systemcatch committed Jul 14, 2019
1 parent 3685d4c commit 17447db
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions arrow/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import absolute_import

import calendar
import warnings
from datetime import date, datetime, tzinfo
from time import struct_time

Expand All @@ -19,6 +20,21 @@
from arrow.util import is_timestamp, isstr


class ArrowParseWarning(DeprecationWarning):
"""Raised when arrow.get() is passed a string with no formats and matches incorrectly
on one of the default formats.
e.g.
arrow.get('blabla2016') -> <Arrow [2016-01-01T00:00:00+00:00]>
arrow.get('13/4/2045') -> <Arrow [2045-01-01T00:00:00+00:00]>
In version 0.15.0 this warning will become a ParserError.
"""


warnings.simplefilter("always", ArrowParseWarning)


class ArrowFactory(object):
""" A factory for generating :class:`Arrow <arrow.arrow.Arrow>` objects.
Expand Down Expand Up @@ -172,6 +188,11 @@ def get(self, *args, **kwargs):

# (str) -> parse.
elif isstr(arg):
warnings.warn(
"The .get() parsing method without a format string will parse more strictly in version 0.15.0."
"See https://github.com/crsmithdev/arrow/issues/612 for more details.",
ArrowParseWarning,
)
dt = parser.DateTimeParser(locale).parse_iso(arg)
return self.type.fromdatetime(dt, tz)

Expand Down Expand Up @@ -214,6 +235,11 @@ def get(self, *args, **kwargs):

# (str, format) -> parse.
elif isstr(arg_1) and (isstr(arg_2) or isinstance(arg_2, list)):
warnings.warn(
"The .get() parsing method with a format string will parse more strictly in version 0.15.0."
"See https://github.com/crsmithdev/arrow/issues/612 for more details.",
ArrowParseWarning,
)
dt = parser.DateTimeParser(locale).parse(args[0], args[1])
return self.type.fromdatetime(dt, tzinfo=tz)

Expand Down

0 comments on commit 17447db

Please sign in to comment.