Skip to content

Commit a075249

Browse files
HSYHSY
authored andcommitted
Fix arrow.get with explicit tzinfo=None
1 parent 2224255 commit a075249

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

arrow/factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,15 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow:
189189
arg_count = len(args)
190190
locale = kwargs.pop("locale", DEFAULT_LOCALE)
191191
tz = kwargs.get("tzinfo", None)
192+
has_tzinfo_kwarg = "tzinfo" in kwargs
192193
normalize_whitespace = kwargs.pop("normalize_whitespace", False)
193194

194195
# if kwargs given, send to constructor unless only tzinfo provided
195196
if len(kwargs) > 1:
196197
arg_count = 3
197198

198199
# tzinfo kwarg is not provided
199-
if len(kwargs) == 1 and tz is None:
200+
if len(kwargs) == 1 and not has_tzinfo_kwarg:
200201
arg_count = 3
201202

202203
# () -> now, @ tzinfo or utc

tests/test_factory.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ def test_kwarg_tzinfo(self):
137137
self.factory.get(tzinfo=ZoneInfo("US/Pacific")), self.expected
138138
)
139139

140+
def test_kwarg_tzinfo_none(self):
141+
assert_datetime_equality(
142+
self.factory.get(tzinfo=None),
143+
datetime.now(timezone.utc).replace(tzinfo=timezone.utc),
144+
)
145+
140146
def test_kwarg_tzinfo_string(self):
141147
self.expected = (
142148
datetime.now(timezone.utc)
@@ -287,6 +293,11 @@ def test_two_args_str_str(self):
287293

288294
assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc())
289295

296+
def test_two_args_str_str_tzinfo_none(self):
297+
result = self.factory.get("2013-01-01", "YYYY-MM-DD", tzinfo=None)
298+
299+
assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc())
300+
290301
def test_two_args_str_tzinfo(self):
291302
result = self.factory.get("2013-01-01", tzinfo=ZoneInfo("US/Pacific"))
292303

0 commit comments

Comments
 (0)