From c719f87bff96e4fee0a1b5c583d18399a878eb00 Mon Sep 17 00:00:00 2001 From: whoami Date: Sun, 7 Jun 2026 12:12:00 +0300 Subject: [PATCH] fix: treat explicit tzinfo=None in get() like an omitted tzinfo get() decided whether the call was constructor-style by checking `tz is None`, which is also true when tzinfo=None is passed explicitly. That routed e.g. get("2025-01-01", "YYYY-MM-DD", tzinfo=None) to the Arrow constructor and raised TypeError. Check whether the tzinfo key is present instead, so passing None behaves the same as omitting it. Fixes #1259 --- arrow/factory.py | 6 ++++-- tests/test_factory.py | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) 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"