arrow-py / arrow-py/arrow

arrow.get() behaviour for tzinfo=None

Open
#1,259 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
9.1k
Forks
784
PR merge metrics
No merged PRs in 30d

Description

## Issue Description

When `arrow.get()` is invoked with a value, a format and a `tzinfo` keyword argument that is `None`, the behavior is different than if the keyword argument were omitted, which is slightly confusing (at least to me).

Example:

```python
d = arrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=account.timezone)
```
where account.timezone is optional and can be None.

This will crash because it will attempt to invoke the 3+ argument constructor of `Arrow`:
```
# 3+ args -> datetime-like via constructor
else:
> return self.type(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: Arrow.__init__() missing 1 required positional argument: 'day'
```

The reason is that in the factory, the check assumes that a single keyword argument and a `None` tzinfo means we've not passed a tzinfo, when in fact we've passed `None`.

```
# tzinfo kwarg is not provided
if len(kwargs) == 1 and tz is None:
arg_count = 3
```

Personally I think explicitly passing `None` as tzinfo should cause it be to treated as 'not passed at all', but I'm not a Python expert, so feel free to close as "works as intended".

## System Info

- 🖥 not relevant
- 🐍 3.13
- 🏹 1.3.0

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate the factory code containing the `len(kwargs) == 1 and tz is None` check and reproduce the `arrow.get()` call with `tzinfo=None` and with the keyword omitted. Add regression coverage showing both forms have the intended behavior, and verify the reported TypeError no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.