Skip to content

fix: handle tzinfo=None kwarg in factory.get() without crashing#1263

Closed
frankgoldfish wants to merge 1 commit intoarrow-py:masterfrom
frankgoldfish:fix/tzinfo-none-kwargs
Closed

fix: handle tzinfo=None kwarg in factory.get() without crashing#1263
frankgoldfish wants to merge 1 commit intoarrow-py:masterfrom
frankgoldfish:fix/tzinfo-none-kwargs

Conversation

@frankgoldfish
Copy link
Copy Markdown

Summary

Fixes #1259.

When tzinfo=None is explicitly passed as a keyword argument to arrow.get(), the factory crashed with:

TypeError: __init__() missing 1 required positional argument: 'day'

Root Cause

In arrow/factory.py, the check:

if len(kwargs) == 1 and tz is None:
    arg_count = 3

incorrectly treats tzinfo=None (explicitly passed) as equivalent to "no tzinfo was passed at all", which forces arg_count = 3 and routes into the positional year/month/day constructor branch — even though no year/month/day args were given.

Fix

Change tz is None to "tzinfo" not in kwargs:

if len(kwargs) == 1 and "tzinfo" not in kwargs:
    arg_count = 3

This correctly distinguishes between:

  • tzinfo kwarg absent → old behavior preserved
  • tzinfo=None explicitly passed → treated as a valid tzinfo value (defaults to UTC)

Reproduction

import arrow

# Before fix: TypeError
# After fix: works correctly
arrow.get("2025-01-01", "YYYY-MM-DD", tzinfo=None)
# Returns: <Arrow [2025-01-01T00:00:00+00:00]>

Real-world pattern: tzinfo=account.timezone where account.timezone is an optional field that may be None.

Tests

Added test_tzinfo_none_kwargs regression test in tests/test_factory.py. All 49 tests pass.

When tzinfo=None is explicitly passed as a keyword argument to arrow.get(),
the factory previously fell through to a branch expecting positional year/month/day
args, raising TypeError.

The check 'len(kwargs) == 1 and tz is None' incorrectly treated explicit
tzinfo=None as equivalent to no tzinfo being passed at all.

Fix: check 'tzinfo not in kwargs' instead of 'tz is None', so that
explicitly passing tzinfo=None is handled as a valid tzinfo value (treated
as UTC, same as omitting it), rather than triggering the wrong branch.

Fixes #1259
@frankgoldfish
Copy link
Copy Markdown
Author

Closing this PR — found that PR #1260 already addresses this issue. Apologies for the duplicate.

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