Skip to content

fix(factory): treat explicit tzinfo=None the same as omitting tzinfo#1277

Open
theohmwoa wants to merge 1 commit into
arrow-py:masterfrom
theohmwoa:fix/1259-tzinfo-none
Open

fix(factory): treat explicit tzinfo=None the same as omitting tzinfo#1277
theohmwoa wants to merge 1 commit into
arrow-py:masterfrom
theohmwoa:fix/1259-tzinfo-none

Conversation

@theohmwoa
Copy link
Copy Markdown

Summary

arrow.get(value, format, tzinfo=None) raised TypeError: Arrow.__init__() missing 1 required positional argument: 'day' because the factory's routing check used the value of tz (which defaults to None) to detect whether the tzinfo kwarg was supplied. When a caller explicitly passed tzinfo=None, the check incorrectly forced arg_count = 3 and routed the call to the multi-arg Arrow(year, month, day, ...) constructor path.

The fix replaces tz is None with "tzinfo" not in kwargs, which actually answers the question the existing comment already promised (# tzinfo kwarg is not provided).

Reproduction

import arrow
arrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=None)
# Before: TypeError: Arrow.__init__() missing 1 required positional argument: 'day'
# After:  <Arrow [2025-01-01T00:00:00+00:00]>

Test

Added TestGet.test_two_args_str_str_tzinfo_none in tests/test_factory.py. It asserts that factory.get("2025-01-01", "YYYY-MM-DD", tzinfo=None) no longer raises, equals factory.get("2025-01-01", "YYYY-MM-DD"), and yields the expected UTC datetime. Full suite passes (1903 tests, 99.93% coverage).

Fixes #1259.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (6a379ef).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1277   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2315           
  Branches       358       358           
=========================================
  Hits          2315      2315           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

arrow.get() behaviour for tzinfo=None

1 participant