Skip to content

Commit

Permalink
Revise typing for min Python 3.10
Browse files Browse the repository at this point in the history
Revisions to typing to benefit from bumping minimum
supported Python version to 3.10.

Removes now superfluous `from __future__ import annotations`
lines and corrects typing syntax errors.
  • Loading branch information
maread99 committed Sep 22, 2024
1 parent 27cde38 commit 3d353a1
Show file tree
Hide file tree
Showing 17 changed files with 11 additions and 29 deletions.
2 changes: 0 additions & 2 deletions etc/factory_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
Module retained in case might be useful.
"""

from __future__ import annotations

import abc
import dataclasses
import pathlib
Expand Down
9 changes: 4 additions & 5 deletions exchange_calendars/calendar_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import contextlib
import datetime
import typing
from typing import Literal
from typing import Literal, TYPE_CHECKING
from zoneinfo import ZoneInfo

import numpy as np
import pandas as pd

from exchange_calendars import errors

if typing.TYPE_CHECKING:
if TYPE_CHECKING:
from exchange_calendars import ExchangeCalendar

UTC = ZoneInfo("UTC")
Expand All @@ -22,15 +21,15 @@

# Use Date type where input does not need to represent an actual session
# and will be parsed by parse_date.
Date = typing.Union[pd.Timestamp, str, int, float, datetime.datetime]
Date = pd.Timestamp | str | int | float | datetime.datetime

# Use Session type where input should represent an actual session and will
# be parsed by parse_session.
Session = Date

# Use Minute type where input does not need to represent an actual trading
# minute and will be parsed by parse_timestamp.
Minute = typing.Union[pd.Timestamp, str, int, float, datetime.datetime]
Minute = pd.Timestamp | str | int | float | datetime.datetime

# Use TradingMinute where input should represent a trading minute and will
# be parsed by parse_trading_minute.
Expand Down
2 changes: 0 additions & 2 deletions exchange_calendars/calendar_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from typing import Literal

from .calendar_helpers import parse_date, Date
Expand Down
2 changes: 2 additions & 0 deletions exchange_calendars/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import typing
import pandas as pd

Expand Down
1 change: 0 additions & 1 deletion exchange_calendars/exchange_calendar_xbud.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import datetime
from zoneinfo import ZoneInfo
Expand Down
1 change: 0 additions & 1 deletion exchange_calendars/exchange_calendar_xbue.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import datetime
from itertools import chain
Expand Down
2 changes: 1 addition & 1 deletion exchange_calendars/exchange_calendar_xkrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations


from datetime import time
import functools
Expand Down
1 change: 0 additions & 1 deletion exchange_calendars/exchange_calendar_xmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import datetime
from itertools import chain
Expand Down
1 change: 0 additions & 1 deletion exchange_calendars/exchange_calendar_xphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import datetime
from itertools import chain
Expand Down
1 change: 0 additions & 1 deletion exchange_calendars/exchange_calendar_xsgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import datetime
from zoneinfo import ZoneInfo
Expand Down
1 change: 0 additions & 1 deletion exchange_calendars/exchange_calendar_xtai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import datetime
from itertools import chain
Expand Down
1 change: 0 additions & 1 deletion exchange_calendars/exchange_calendar_xwar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import datetime
from zoneinfo import ZoneInfo
Expand Down
1 change: 0 additions & 1 deletion exchange_calendars/precomputed_exchange_calendar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import annotations
from abc import abstractmethod

import numpy as np
Expand Down
2 changes: 0 additions & 2 deletions exchange_calendars/utils/pandas_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import datetime
from zoneinfo import ZoneInfo

Expand Down
2 changes: 0 additions & 2 deletions exchange_calendars/xbkk_holidays.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import datetime

import pandas as pd
Expand Down
2 changes: 0 additions & 2 deletions tests/test_calendar_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Tests for calendar_helpers module."""

from __future__ import annotations

from collections import abc
import datetime
from datetime import time
Expand Down
9 changes: 4 additions & 5 deletions tests/test_exchange_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

from collections import abc
from datetime import time
Expand Down Expand Up @@ -722,7 +721,7 @@ def _get_sessions_with_times_different_to_next_session(
Returns
-------
list of pd.Datetimeindex
list of pd.DatetimeIndex
[0] sessions with earlier next session
[1] sessions with later next session
"""
Expand Down Expand Up @@ -1117,12 +1116,12 @@ def non_sessions(self) -> pd.DatetimeIndex:
@property
def sessions_range_defined_by_non_sessions(
self,
) -> tuple[tuple[pd.Timestamp, pd.Timestamp], pd.Datetimeindex] | None:
) -> tuple[tuple[pd.Timestamp, pd.Timestamp], pd.DatetimeIndex] | None:
"""Range containing sessions although defined with non-sessions.
Returns
-------
tuple[tuple[pd.Timestamp, pd.Timestamp], pd.Datetimeindex]:
tuple[tuple[pd.Timestamp, pd.Timestamp], pd.DatetimeIndex]:
[0] tuple[pd.Timestamp, pd.Timestamp]:
[0] range start as non-session date.
[1] range end as non-session date.
Expand Down Expand Up @@ -1869,7 +1868,7 @@ def early_closes_sample_time(self) -> abc.Iterator[pd.Timedelta | None]:
yield None

@pytest.fixture
def early_closes_weekdays(self) -> abc.Iterator[tuple(int)]:
def early_closes_weekdays(self) -> abc.Iterator[tuple[int]]:
"""Weekdays with non-standard close times.
`test_early_closes_weekdays` will check that all sessions on these
Expand Down

0 comments on commit 3d353a1

Please sign in to comment.