diff --git a/arrow/factory.py b/arrow/factory.py index 0913bfe1..ca74d19b 100644 --- a/arrow/factory.py +++ b/arrow/factory.py @@ -195,8 +195,10 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow: if len(kwargs) > 1: arg_count = 3 - # tzinfo kwarg is not provided - if len(kwargs) == 1 and tz is None: + # the single remaining kwarg is for the constructor, not tzinfo + # (checking "tzinfo" not in kwargs so an explicit tzinfo=None is + # treated like an omitted tzinfo instead of a constructor argument) + if len(kwargs) == 1 and "tzinfo" not in kwargs: arg_count = 3 # () -> now, @ tzinfo or utc diff --git a/tests/test_factory.py b/tests/test_factory.py index 056cee41..26e3bc7f 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -315,6 +315,15 @@ def test_two_args_other(self): with pytest.raises(TypeError): self.factory.get(object(), object()) + # regression test for issue #1259 + def test_explicit_tzinfo_none(self): + # passing tzinfo=None should behave the same as omitting it, rather + # than routing the call to the Arrow constructor + expected = datetime(2013, 1, 1, tzinfo=tz.tzutc()) + + assert self.factory.get("2013-01-01", "YYYY-MM-DD", tzinfo=None) == expected + assert self.factory.get("2013-01-01", tzinfo=None) == expected + def test_three_args_with_tzinfo(self): timefmt = "YYYYMMDD" d = "20150514"