arrow-py / arrow-py/arrow

Type hints for `Arrow.interval` should show `Arrow` as possible type for `start` and `end` arguments

Open
#1,210 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

Currently, footprint for `Arrow.interval` is:
```py
def interval(
cls,
frame: _T_FRAMES,
start: dt_datetime,
end: dt_datetime,
interval: int = 1,
tz: Optional[TZ_EXPR] = None,
bounds: _BOUNDS = "[)",
exact: bool = False,
) -> Iterable[Tuple["Arrow", "Arrow"]]:
```
Despite the fact that `start` and `end` arguments have type `dt_datetime` (which is `datetime.datetime`) however, both of them accept `Arrow` objects, which, looking down the line, makes sense, as the only properties of these arguments that are used are shared between `Arrow` and `dt_datetime` and (see `fromdatetime` method).
Thus, i believe it would make sense to change type hints for both arguments to the union of `Arrow` and `dt_datetime`:
```py
def interval(
cls,
frame: _T_FRAMES,
start: "Arrow" | dt_datetime,
end: "Arrow" | dt_datetime,
interval: int = 1,
tz: Optional[TZ_EXPR] = None,
bounds: _BOUNDS = "[)",
exact: bool = False,
) -> Iterable[Tuple["Arrow", "Arrow"]]:
```

## System Info

- 🖥 **OS name and version**: Windows 24H2 26100.3476
- 🐍 **Python version**: 3.10.11
- 🏹 **Arrow version**: 1.3.0

Contributor guide

No contributing guide indexed for this repository

Research direction

Find the implementation and type annotation for Arrow.interval, then inspect any nearby tests covering interval inputs. Verify how Arrow and datetime values are accepted before updating the start and end annotations. Done means the public signature advertises both accepted types and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.