Skip to content

Commit 058d6fa

Browse files
committed
Add mypy to pre-commit and fix the errors
Limit the Python version to =3.10 because of the `pandas-stubs` typing dependency, see: pandas-dev/pandas-stubs#400 Poetry command: ```sh poetry add -G typing mypy pandas-stubs ``` Add the recommended settings for mypy: https://blog.wolt.com/engineering/2021/09/30/professional-grade-mypy-configuration/ Fix the errors with type ignore as they originate from wrong typing in pandas/builtin libs and make sure mypy passes: ```sh pre-commit run mypy --all-files ```
1 parent 8bc3a55 commit 058d6fa

File tree

6 files changed

+129
-10
lines changed

6 files changed

+129
-10
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ repos:
2525
entry: poetry run pylint
2626
language: system
2727
types: [python]
28+
- id: mypy
29+
name: mypy
30+
entry: poetry run mypy
31+
language: system
32+
types: [python]

poetry.lock

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

pyproject.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ classifiers = [
2626
]
2727

2828
[tool.poetry.dependencies]
29-
python = "^3.10"
29+
python = ">= 3.10, < 3.11"
3030
pandas = "^1.5.1"
3131
beautifulsoup4 = {version = "^4.11.1", extras = ["lxml", "html5lib"]}
3232

3333
[tool.poetry.group.dev.dependencies]
3434
pre-commit = "^2.20.0"
3535
pylint = "^2.15.6"
3636

37+
[tool.poetry.group.typing.dependencies]
38+
mypy = "^0.991"
39+
pandas-stubs = "^1.5.1.221024"
40+
3741
[tool.poetry.urls]
3842
"Bug Tracker" = "https://github.com/jond01/xil/issues"
3943

@@ -43,6 +47,13 @@ profile = "black"
4347
[tool.pylint]
4448
enable = ["I"]
4549

50+
[tool.mypy]
51+
check_untyped_defs = true
52+
disallow_untyped_defs = true
53+
warn_unused_ignores = true
54+
warn_return_any = true
55+
show_error_codes = true
56+
4657
[build-system]
4758
requires = ["poetry-core"]
4859
build-backend = "poetry.core.masonry.api"

xil/_headers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def get_url_response(
2424
else:
2525
headers = {}
2626
request = urllib.request.Request(url, headers=headers)
27-
return urllib.request.urlopen(request)
27+
return urllib.request.urlopen(request) # type: ignore[no-any-return]

xil/fibi.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626

2727
with get_url_response(_FIBI_URL) as response:
2828
dfs = pd.read_html(
29-
response, match=_MATCH, header=_HEADER, encoding=_ENCODING, attrs=_ATTRS
29+
response, # type: ignore[arg-type]
30+
match=_MATCH,
31+
header=_HEADER,
32+
encoding=_ENCODING,
33+
attrs=_ATTRS,
3034
)
3135

3236
df = dfs[0] # It is guaranteed to have at least one element - otherwise an exception

xil/union.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_HEADER = [0, 1]
2525

2626
with get_url_response(_UNION_URL, headers=_UNION_HEADERS) as response:
27-
df = pd.read_html(response, header=_HEADER)[0]
27+
df = pd.read_html(response, header=_HEADER)[0] # type: ignore[arg-type]
2828

2929
df = df.drop(("Unnamed: 7_level_0", "מכירה"), axis=1) # empty (NaNs) column
3030

0 commit comments

Comments
 (0)