Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions arrow/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ def get(
) -> Arrow: ... # pragma: no cover


@overload
def get(
year: int,
month: int,
day: int,
hour: int = 0,
minute: int = 0,
second: int = 0,
microsecond: int = 0,
tzinfo: Optional[TZ_EXPR] = None,
*,
fold: int = 0,
locale: str = DEFAULT_LOCALE,
normalize_whitespace: bool = False,
) -> Arrow: ... # pragma: no cover


def get(*args: Any, **kwargs: Any) -> Arrow:
"""Calls the default :class:`ArrowFactory <arrow.factory.ArrowFactory>` ``get`` method."""

Expand Down
17 changes: 17 additions & 0 deletions arrow/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ def get(
normalize_whitespace: bool = False,
) -> Arrow: ... # pragma: no cover

@overload
def get(
self,
year: int,
month: int,
day: int,
hour: int = 0,
minute: int = 0,
second: int = 0,
microsecond: int = 0,
tzinfo: Optional[TZ_EXPR] = None,
*,
fold: int = 0,
locale: str = DEFAULT_LOCALE,
normalize_whitespace: bool = False,
) -> Arrow: ... # pragma: no cover

def get(self, *args: Any, **kwargs: Any) -> Arrow:
"""Returns an :class:`Arrow <arrow.arrow.Arrow>` object based on flexible inputs.

Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ allow_redefinition = True
# Type annotations for testing code and migration files are not mandatory
[mypy-*.tests.*,tests.*]
ignore_errors = True

[mypy-tests.type_checks]
ignore_errors = False
33 changes: 33 additions & 0 deletions tests/type_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Static regression checks, validated by the mypy pre-commit hook."""

from datetime import timezone
from typing import List

import arrow
from arrow.factory import ArrowFactory


def check_get_constructor_overloads() -> List[arrow.Arrow]:
factory = ArrowFactory()
return [
factory.get(2024, 6, 1),
factory.get(year=2024, month=6, day=1),
factory.get(2024, month=6, day=1, hour=12),
factory.get(2024, 6, 1, 12, 30, 45, 123456, "UTC"),
factory.get(2024, 6, 1, tzinfo=timezone.utc, fold=1),
factory.get(year=2024, month=6, day=1, locale="en", normalize_whitespace=True),
arrow.get(2024, 6, 1),
arrow.get(year=2024, month=6, day=1),
arrow.get(2024, month=6, day=1, hour=12),
arrow.get(2024, 6, 1, 12, 30, 45, 123456, "UTC"),
arrow.get(2024, 6, 1, tzinfo=timezone.utc, fold=1),
arrow.get(year=2024, month=6, day=1, locale="en", normalize_whitespace=True),
]


def check_invalid_constructor_calls() -> None:
factory = ArrowFactory()
factory.get(year=2024, month=6) # type: ignore[call-overload]
factory.get(year=2024, month=6, day="1") # type: ignore[call-overload]
arrow.get(year=2024, month=6) # type: ignore[call-overload]
arrow.get(year=2024, month=6, day="1") # type: ignore[call-overload]
Loading