Skip to content

arrow.get() behaviour for tzinfo=None #1259

@suzukieng

Description

@suzukieng

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions