Skip to content

fix(types): use Union[Arrow, dt_datetime] for span_range and interval start/end params#1267

Open
juliosuas wants to merge 3 commits intoarrow-py:masterfrom
juliosuas:fix/span-range-interval-type-hints
Open

fix(types): use Union[Arrow, dt_datetime] for span_range and interval start/end params#1267
juliosuas wants to merge 3 commits intoarrow-py:masterfrom
juliosuas:fix/span-range-interval-type-hints

Conversation

@juliosuas
Copy link
Copy Markdown

Problem

Arrow.span_range() and Arrow.interval() accept both Arrow and datetime objects for their start/end parameters (they pass through fromdatetime() internally), but their type hints only declare dt_datetime.

This means type checkers (mypy, pyright) raise false errors when passing Arrow objects directly:

start = arrow.now()
end = arrow.now().shift(hours=24)
list(arrow.Arrow.span_range('hour', start, end))  # ← mypy: error: Argument 2 to 'span_range' has incompatible type 'Arrow'; expected 'datetime'

Fix

Arrow.range() already uses the correct type Union['Arrow', dt_datetime] for its start/end params. This PR applies the same fix to span_range() and interval() for consistency.

# Before
start: dt_datetime,
end: dt_datetime,

# After  
start: Union['Arrow', dt_datetime],
end: Union['Arrow', dt_datetime],

Fixes #1210.

… start/end params

Arrow.range() already typed start/end as Union['Arrow', dt_datetime] since both
types work via fromdatetime() internally. span_range() and interval() accept the
same union but were typed as dt_datetime only, causing mypy/pyright errors when
passing Arrow objects directly.

Aligns the type signatures of all three class methods for consistency.

Fixes arrow-py#1210.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b423717) to head (1e96211).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1267   +/-   ##
=========================================
  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.

…ime calls

fromdatetime() only accepts datetime, not Arrow. span_range and interval
now call cls._get_datetime(start/end) to convert Arrow objects to their
underlying datetime before passing to fromdatetime — matching the pattern
already used in Arrow.range().

This satisfies mypy while preserving the Union[Arrow, dt_datetime] type
hint on the public API.
@juliosuas
Copy link
Copy Markdown
Author

😁

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.

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

1 participant