From dc73690c4b0f89613d965e2d248afe6979bdbe0c Mon Sep 17 00:00:00 2001 From: mayuriphad Date: Thu, 20 Aug 2026 18:30:54 +0530 Subject: [PATCH] Fix arrow.get() crash when tzinfo kwarg is explicitly None The kwarg-count check in ArrowFactory.get() used 'tz is None' to detect that only the tzinfo kwarg was passed, so it could fall back to the 3+ positional-argument constructor path. This meant an explicitly passed tzinfo=None (as opposed to omitting the kwarg entirely) was misidentified, and arrow.get(, , tzinfo=None) incorrectly routed to self.type(*args, **kwargs), raising a confusing TypeError about a missing 'day' argument instead of parsing the string as expected. Check for the key's presence instead of its value. Fixes #1259 --- arrow/factory.py | 2 +- tests/test_factory.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arrow/factory.py b/arrow/factory.py index 0913bfe1b..dc31c66dd 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 056cee412..a28f356e4 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -149,6 +149,17 @@ def test_kwarg_tzinfo_string(self): with pytest.raises(ParserError): self.factory.get(tzinfo="US/PacificInvalidTzinfo") + def test_kwarg_tzinfo_none_with_string_and_format(self): + # Passing tzinfo=None explicitly, alongside a string and a format, + # should behave the same as not passing tzinfo at all (i.e. parse + # the string using the given format, defaulting to UTC), rather + # than being treated as a 3+ arg direct-constructor call. + result = self.factory.get("2013-01-01", "YYYY-MM-DD", tzinfo=None) + expected = self.factory.get("2013-01-01", "YYYY-MM-DD") + + assert result._datetime == expected._datetime + assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) + def test_kwarg_normalize_whitespace(self): result = self.factory.get( "Jun 1 2005 1:33PM",