Skip to content

Commit d383f04

Browse files
authored
Merge pull request #482 from weaviate/fix-clientwide-mypy-errors
Fix clientwide mypy errors
2 parents f6715fc + 41533c8 commit d383f04

23 files changed

+252
-145
lines changed

.github/workflows/main.yaml

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ on:
1414
pull_request:
1515

1616
jobs:
17-
lint-and_format:
18-
name: Run linter and formatter
17+
lint-and-format:
18+
name: Run Linter and Formatter
1919
runs-on: ubuntu-latest
2020
steps:
2121
- uses: actions/checkout@v3
@@ -34,6 +34,24 @@ jobs:
3434
python -m build
3535
python -m twine check dist/*
3636
37+
type-checking:
38+
name: Run Type Checking
39+
runs-on: ubuntu-latest
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
version: ["3.8", "3.9", "3.10", "3.11"]
44+
folder: ["weaviate"]
45+
steps:
46+
- uses: actions/checkout@v3
47+
- uses: actions/setup-python@v4
48+
with:
49+
python-version: "3.11"
50+
cache: 'pip' # caching pip dependencies
51+
- run: pip install -r requirements-devel.txt
52+
- name: Run mypy
53+
run: mypy --python-version ${{matrix.version}} ${{ matrix.folder }}
54+
3755
unit-tests:
3856
name: Run Unit Tests
3957
runs-on: ubuntu-latest
@@ -43,20 +61,20 @@ jobs:
4361
version: ["3.8", "3.9", "3.10", "3.11"]
4462
folder: ["test", "mock_tests"]
4563
steps:
46-
- uses: actions/checkout@v3
47-
- uses: actions/setup-python@v4
48-
with:
49-
python-version: ${{ matrix.version }}
50-
cache: 'pip' # caching pip dependencies
51-
- run: pip install -r requirements-devel.txt
52-
- name: Run unittests
53-
run: pytest --cov -v --cov-report=term-missing --cov=weaviate --cov-report xml:coverage-${{ matrix.folder }}.xml ${{ matrix.folder }}
54-
- name: Archive code coverage results
55-
if: matrix.version == '3.10' && (github.ref_name != 'main')
56-
uses: actions/upload-artifact@v3
57-
with:
58-
name: coverage-report-${{ matrix.folder }}
59-
path: coverage-${{ matrix.folder }}.xml
64+
- uses: actions/checkout@v3
65+
- uses: actions/setup-python@v4
66+
with:
67+
python-version: ${{ matrix.version }}
68+
cache: 'pip' # caching pip dependencies
69+
- run: pip install -r requirements-devel.txt
70+
- name: Run unittests
71+
run: pytest --cov -v --cov-report=term-missing --cov=weaviate --cov-report xml:coverage-${{ matrix.folder }}.xml ${{ matrix.folder }}
72+
- name: Archive code coverage results
73+
if: matrix.version == '3.10' && (github.ref_name != 'main')
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: coverage-report-${{ matrix.folder }}
77+
path: coverage-${{ matrix.folder }}.xml
6078

6179
integration-tests:
6280
name: Run Integration Tests
@@ -185,7 +203,7 @@ jobs:
185203

186204
build-and-publish:
187205
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
188-
needs: [integration-tests, unit-tests, lint-and_format, test-package]
206+
needs: [integration-tests, unit-tests, lint-and-format, type-checking, test-package]
189207
runs-on: ubuntu-latest
190208
steps:
191209
- name: Checkout

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,16 @@ repos:
1919
'flake8-bugbear==22.10.27',
2020
'flake8-comprehensions==3.10.1',
2121
'flake8-builtins==2.0.1'
22+
]
23+
24+
- repo: https://github.com/pre-commit/mirrors-mypy
25+
rev: "v1.5.1"
26+
hooks:
27+
- id: mypy
28+
entry: mypy ./weaviate
29+
pass_filenames: false
30+
additional_dependencies: [
31+
'types-requests==2.31.0.2',
32+
'types-urllib3==1.26.25.14',
33+
'typing_extensions==4.7.1',
2234
]

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ warn_return_any = true
3434
warn_unused_ignores = true
3535
exclude = ["weaviate_grpc", "docs", "mock_tests", "test", "integration"]
3636

37+
[[tool.mypy.overrides]]
38+
module = "weaviate_grpc.*"
39+
ignore_errors = true
40+
3741
[[tool.mypy.overrides]]
3842
module = "grpc.*"
3943
ignore_missing_imports = true

requirements-devel.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ coverage==7.3.0
2020
werkzeug>=2.3.7
2121
pytest-httpserver>=1.0.8
2222

23+
mypy>=1.5.1<2.0.0
24+
mypy-extensions==1.0.0
25+
tomli>=2.0.1<3.0.0
26+
types-requests>=2.31.0.2<3.0.0
27+
types-urllib3>=1.26.25.14<2.0.0
28+
typing_extensions>=4.7.1<5.0.0
29+
2330
pre-commit
2431

2532
flake8

test/gql/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_raw(self):
3535
"""
3636

3737
# valid calls
38-
connection_mock = mock_connection_func("post")
38+
connection_mock = mock_connection_func("post", return_json={})
3939
query = Query(connection_mock)
4040

4141
gql_query = "{Get {Group {name Members {... on Person {name}}}}}"

weaviate/backup/backup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def create(
118118
) from conn_err
119119

120120
create_status = _decode_json_response_dict(response, "Backup creation")
121+
assert create_status is not None
121122
if wait_for_completion:
122123
while True:
123124
status: dict = self.get_create_status(
@@ -246,7 +247,7 @@ def restore(
246247
"Backup restore failed due to connection error."
247248
) from conn_err
248249
restore_status = _decode_json_response_dict(response, "Backup restore")
249-
250+
assert restore_status is not None
250251
if wait_for_completion:
251252
while True:
252253
status: dict = self.get_restore_status(

0 commit comments

Comments
 (0)