From cba31fde812ab7b19c43a79853b0acd2b5fb53c4 Mon Sep 17 00:00:00 2001 From: Frank Goldfish Date: Mon, 16 Mar 2026 17:23:45 -0700 Subject: [PATCH] fix: handle tzinfo=None kwarg in factory.get() without crashing When tzinfo=None is explicitly passed as a keyword argument to arrow.get(), the factory previously fell through to a branch expecting positional year/month/day args, raising TypeError. The check 'len(kwargs) == 1 and tz is None' incorrectly treated explicit tzinfo=None as equivalent to no tzinfo being passed at all. Fix: check 'tzinfo not in kwargs' instead of 'tz is None', so that explicitly passing tzinfo=None is handled as a valid tzinfo value (treated as UTC, same as omitting it), rather than triggering the wrong branch. Fixes #1259 --- arrow/factory.py | 2 +- tests/test_factory.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arrow/factory.py b/arrow/factory.py index 0913bfe1..dc31c66d 100644 --- a/arrow/factory.py +++ b/arrow/factory.py @@ -196,7 +196,7 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow: arg_count = 3 # tzinfo kwarg is not provided - if len(kwargs) == 1 and tz is None: + 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..682a2243 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -346,6 +346,12 @@ def test_tzinfo_string_kwargs(self): result = self.factory.get("2019072807", "YYYYMMDDHH", tzinfo="UTC") assert result._datetime == datetime(2019, 7, 28, 7, 0, 0, 0, tzinfo=tz.tzutc()) + def test_tzinfo_none_kwargs(self): + # regression test for issue #1259 + # passing tzinfo=None explicitly should not raise TypeError + result = self.factory.get("2025-01-01", "YYYY-MM-DD", tzinfo=None) + assert result._datetime == datetime(2025, 1, 1, 0, 0, 0, 0, tzinfo=tz.tzutc()) + def test_insufficient_kwargs(self): with pytest.raises(TypeError): self.factory.get(year=2016)