diff --git a/arrow/factory.py b/arrow/factory.py index 0913bfe1..355234af 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: + # tzinfo kwarg is not provided (explicit tzinfo=None is treated as not provided) + 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..4b20d064 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -287,6 +287,24 @@ 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): + # Regression test for issue #1259: + # Explicitly passing tzinfo=None must behave identically to omitting tzinfo. + # Previously this crashed with TypeError because len(kwargs)==1 and tz is None + # triggered the 3+ arg constructor path instead of the 2-arg str+format parse path. + result = self.factory.get("2025-01-01", "YYYY-MM-DD", tzinfo=None) + assert result._datetime == datetime(2025, 1, 1, tzinfo=tz.tzutc()) + + def test_no_args_tzinfo_none(self): + # Regression test for issue #1259: + # arrow.get(tzinfo=None) must return current UTC time, same as arrow.get(). + from arrow.util import is_timestamp + result = self.factory.get(tzinfo=None) + now_utc = self.factory.utcnow() + # Allow a 2-second window to avoid flakiness + assert abs((result - now_utc).total_seconds()) < 2 + + def test_two_args_str_tzinfo(self): result = self.factory.get("2013-01-01", tzinfo=ZoneInfo("US/Pacific"))