Skip to content

Commit 0513fe7

Browse files
committed
Add mypy auto check and fix easy errors
Summary: Add mypy automated check and fix any of the easy errors that don't result in functional changes Test Plan: Run `mypy functional`
1 parent 0a03ee9 commit 0513fe7

File tree

7 files changed

+61
-108
lines changed

7 files changed

+61
-108
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.9"]
18+
python-version: ["3.8", "3.9", "3.10", "3.11", "pypy3.9"]
1919
include:
2020
- python-version: "3.11"
2121
use_pandas: 1
@@ -35,6 +35,9 @@ jobs:
3535
- name: Test with pytest
3636
run: poetry run pytest --cov=functional --cov-report=xml
3737
if: always()
38+
- name: mypy
39+
run: poetry run mypy functional
40+
if: always()
3841
- uses: codecov/codecov-action@v1
3942
with:
4043
file: ./coverage.xml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ In order to be merged, all pull requests must:
489489
[Gitter for chat](https://gitter.im/EntilZha/PyFunctional)
490490

491491
## Supported Python Versions
492-
* `PyFunctional` 1.5 is tested against Python 3.7 to 3.11 and PyPy3
492+
* `PyFunctional` 1.5 is tested against Python 3.8 to 3.11 and PyPy3
493493
* `PyFunctional` 1.4 supports and is tested against Python 3.6, Python 3.7, and PyPy3
494494
* `PyFunctional` 1.4 and above do not support python 2.7
495495
* `PyFunctional` 1.4 works in Python 3.5, but is not tested against it

functional/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def get_read_function(filename: str, disable_compression: bool):
288288
with open(filename, "rb") as f:
289289
start_bytes = f.read(N_COMPRESSION_CHECK_BYTES)
290290
for cls in COMPRESSION_CLASSES:
291-
if cls.is_compressed(start_bytes):
291+
if cls.is_compressed(start_bytes): # type: ignore
292292
return cls
293293
return ReusableFile
294294

functional/pipeline.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212

1313
from collections.abc import Iterable
14-
from typing import Optional
14+
from typing import List, Optional, Tuple, Union
1515

1616
from tabulate import tabulate
1717

@@ -40,7 +40,7 @@ def __init__(
4040
self,
4141
sequence: Iterable,
4242
transform=None,
43-
engine: ExecutionEngine = None,
43+
engine: Optional[ExecutionEngine] = None,
4444
max_repr_items: Optional[int] = None,
4545
no_wrap: Optional[bool] = None,
4646
):
@@ -59,9 +59,13 @@ def __init__(
5959
"""
6060
self.engine = engine or ExecutionEngine()
6161
if isinstance(sequence, Sequence):
62-
self._max_repr_items = max_repr_items or sequence._max_repr_items
63-
self._base_sequence = sequence._base_sequence
64-
self._lineage = Lineage(prior_lineage=sequence._lineage, engine=engine)
62+
self._max_repr_items: Optional[int] = (
63+
max_repr_items or sequence._max_repr_items
64+
)
65+
self._base_sequence: Union[Iterable, List, Tuple] = sequence._base_sequence
66+
self._lineage: Lineage = Lineage(
67+
prior_lineage=sequence._lineage, engine=engine
68+
)
6569
elif isinstance(sequence, (list, tuple)) or is_iterable(sequence):
6670
self._max_repr_items = max_repr_items
6771
self._base_sequence = sequence

functional/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from functools import reduce
44
from itertools import chain, count, islice, takewhile
55
from multiprocessing import Pool, cpu_count
6+
from typing import Any
67

7-
import dill as serializer
8+
import dill as serializer # type: ignore
89

910

1011
PROTOCOL = serializer.HIGHEST_PROTOCOL
@@ -188,7 +189,7 @@ def compose(*functions):
188189
return reduce(lambda f, g: lambda x: f(g(x)), functions, lambda x: x)
189190

190191

191-
def default_value(*vals: tuple):
192+
def default_value(*vals: Any):
192193
for val in vals:
193194
if val is not None:
194195
return val

poetry.lock

Lines changed: 40 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ classifiers = [
1414
'Development Status :: 5 - Production/Stable',
1515
'Intended Audience :: Developers',
1616
'License :: OSI Approved :: MIT License',
17-
'Programming Language :: Python :: 3.7',
1817
'Programming Language :: Python :: 3.8',
1918
'Programming Language :: Python :: 3.9',
2019
'Programming Language :: Python :: 3.10',
@@ -28,7 +27,7 @@ classifiers = [
2827
packages = [{ include = "functional" }]
2928

3029
[tool.poetry.dependencies]
31-
python = "^3.7.2"
30+
python = "^3.8.0"
3231
dill = ">=0.2.5"
3332
tabulate = "<=1.0.0"
3433
pandas = { version = "^1.0.3", optional = true }
@@ -45,6 +44,8 @@ coverage = "^7.2.5"
4544

4645
[tool.poetry.group.dev.dependencies]
4746
mypy = "^1.1.1"
47+
types-tabulate = "^0.9.0.3"
48+
pandas-stubs = "^2.0.3.230814"
4849

4950
[build-system]
5051
requires = ["poetry>=0.12"]

0 commit comments

Comments
 (0)