From ca6f219d84a6262ec8c2ae9964eb2eab7d94aaf1 Mon Sep 17 00:00:00 2001 From: Rex Kirshner Date: Thu, 12 Mar 2026 07:53:50 -0700 Subject: [PATCH] Fix arrow.get() crash when tzinfo=None is explicitly passed The condition for detecting non-tzinfo kwargs checked `tz is None` instead of whether 'tzinfo' was actually absent from kwargs. This caused `arrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=None)` to incorrectly bump arg_count to 3, falling through to the constructor path and raising TypeError. Fixes #1259 Co-Authored-By: Claude Opus 4.6 --- arrow/factory.py | 4 ++-- tests/test_factory.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arrow/factory.py b/arrow/factory.py index 0913bfe1b..ff59dbded 100644 --- a/arrow/factory.py +++ b/arrow/factory.py @@ -195,8 +195,8 @@ 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: + # one non-tzinfo kwarg is provided, send to constructor + 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..84ff10080 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -23,6 +23,12 @@ def test_no_args(self): self.factory.get(), datetime.now(timezone.utc).replace(tzinfo=timezone.utc) ) + def test_no_args_tzinfo_none(self): + assert_datetime_equality( + self.factory.get(tzinfo=None), + datetime.now(timezone.utc).replace(tzinfo=timezone.utc), + ) + def test_timestamp_one_arg_no_arg(self): no_arg = self.factory.get(1406430900).timestamp() one_arg = self.factory.get("1406430900", "X").timestamp() @@ -208,6 +214,11 @@ def test_one_arg_iso_str(self): assert_datetime_equality(self.factory.get(dt.isoformat()), dt) + def test_one_arg_str_tzinfo_none(self): + result = self.factory.get("2013-01-01", tzinfo=None) + + assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) + def test_one_arg_iso_calendar(self): pairs = [ (datetime(2004, 1, 4), (2004, 1, 7)), @@ -287,6 +298,11 @@ def test_two_args_str_str(self): assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) + def test_two_args_str_str_tzinfo_none(self): + result = self.factory.get("2013-01-01", "YYYY-MM-DD", tzinfo=None) + + assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) + def test_two_args_str_tzinfo(self): result = self.factory.get("2013-01-01", tzinfo=ZoneInfo("US/Pacific"))