Skip to content

Commit e4249f5

Browse files
authored
Merge pull request #169 from bdrung/mypy
Add type hints to dicts
2 parents d5a7f0e + c5fc286 commit e4249f5

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

.github/workflows/cicd.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ jobs:
2828
uses: actions/setup-python@v5
2929
with: {python-version: "${{ matrix.python-version }}", cache: pip, cache-dependency-path: 'requirements/*.txt'}
3030
- name: install tests dependencies
31-
run: pip install -r requirements/test.txt -r requirements/lint.txt -r requirements/tox.txt -r requirements/format.txt
31+
run: pip install -r requirements/test.txt -r requirements/lint.txt -r requirements/mypy.txt -r requirements/tox.txt -r requirements/format.txt
3232
- name: formatters check
33-
run: tox --current-env -e lint,fmt
33+
run: tox --current-env -e lint,mypy,fmt
3434

3535
test-py3:
3636
runs-on: ubuntu-latest
@@ -67,4 +67,3 @@ jobs:
6767
docker compose build --build-arg BASE=corpusops/croniter:32bits
6868
docker compose run --rm app tox --current-env -e test
6969
env: {COMPOSE_FILE: "docker-compose.yml:docker-compose-32bits.yml"}
70-

requirements/mypy.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mypy
2+
types-python-dateutil
3+
types-pytz

src/croniter/croniter.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import sys
1212
import traceback as _traceback
1313
from time import time
14+
from typing import Optional, Union
1415

1516
from dateutil.relativedelta import relativedelta
1617
from dateutil.tz import tzutc
@@ -59,12 +60,12 @@ def is_32bit():
5960
EPOCH = datetime.datetime.fromtimestamp(0, UTC_DT)
6061

6162
# fmt: off
62-
M_ALPHAS = {
63+
M_ALPHAS: dict[str, Union[int, str]] = {
6364
"jan": 1, "feb": 2, "mar": 3, "apr": 4, # noqa: E241
6465
"may": 5, "jun": 6, "jul": 7, "aug": 8, # noqa: E241
6566
"sep": 9, "oct": 10, "nov": 11, "dec": 12,
6667
}
67-
DOW_ALPHAS = {
68+
DOW_ALPHAS: dict[str, Union[int, str]] = {
6869
"sun": 0, "mon": 1, "tue": 2, "wed": 3, "thu": 4, "fri": 5, "sat": 6
6970
}
7071

@@ -109,8 +110,8 @@ def is_32bit():
109110
YEAR_CRON_LEN = len(YEAR_FIELDS)
110111
# retrocompat
111112
VALID_LEN_EXPRESSION = {a for a in CRON_FIELDS if isinstance(a, int)}
112-
TIMESTAMP_TO_DT_CACHE = {}
113-
EXPRESSIONS = {}
113+
TIMESTAMP_TO_DT_CACHE: dict[int, datetime.datetime] = {}
114+
EXPRESSIONS: dict[tuple[str, Optional[bytes], bool], list[str]] = {}
114115
MARKER = object()
115116

116117

@@ -176,7 +177,7 @@ class croniter:
176177
(1970, 2099),
177178
)
178179

179-
ALPHACONV = (
180+
ALPHACONV: tuple[dict[str, Union[int, str]], ...] = (
180181
{}, # 0: min
181182
{}, # 1: hour
182183
{"l": "l"}, # 2: dom
@@ -190,7 +191,7 @@ class croniter:
190191
{},
191192
)
192193

193-
LOWMAP = (
194+
LOWMAP: tuple[dict[int, int], ...] = (
194195
{},
195196
{},
196197
{0: 1},

src/croniter/tests/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import typing
12
import unittest
23

34

@@ -7,4 +8,4 @@ class TestCase(unittest.TestCase):
78
If necessary, we can put common utility or setup code in here.
89
"""
910

10-
maxDiff = 10**10
11+
maxDiff: typing.Optional[int] = 10**10

tox.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ deps = -r{toxinidir}/requirements/lint.txt
1717
changedir = src
1818
commands = flake8 croniter/croniter.py
1919

20+
[testenv:mypy]
21+
deps = -r{toxinidir}/requirements/mypy.txt
22+
commands = mypy .
23+
2024
[testenv:fmt]
2125
deps = -r{toxinidir}/requirements/format.txt
2226
changedir = src

0 commit comments

Comments
 (0)