From 99128b507b77532af3fb52b093254546a15ef510 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Thu, 10 Oct 2024 22:45:31 +0100 Subject: [PATCH] Make config test options not unknown types (#252) * Make config test options not unknown types * Run pyright as part of tests --- .github/workflows/test.yml | 6 ++++-- dj_database_url/__init__.py | 6 +++--- pyproject.toml | 3 +++ requirements.txt | 1 + setup.py | 2 +- tests/test_dj_database_url.py | 2 ++ 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09fa7ce..30ea045 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,9 +39,10 @@ jobs: pip install -r requirements.txt pip install "Django~=${{ matrix.django-version }}.0" . - - name: Run mypy + - name: Run type checking run: | python -m mypy dj_database_url + python -m pyright dj_database_url - name: Run Tests run: | @@ -52,8 +53,9 @@ jobs: - uses: codecov/codecov-action@v3 - - name: Check mypy types installation + - name: Check types installation run: | pip install . cd tests python -m mypy . + python -m pyright . diff --git a/dj_database_url/__init__.py b/dj_database_url/__init__.py index d620a3d..2bf9d21 100644 --- a/dj_database_url/__init__.py +++ b/dj_database_url/__init__.py @@ -41,7 +41,7 @@ # Register database schemes in URLs. for key in SCHEMES.keys(): urlparse.uses_netloc.append(key) -del key +del key # pyright: ignore[reportPossiblyUnboundVariable] # From https://docs.djangoproject.com/en/4.0/ref/settings/#databases @@ -70,7 +70,7 @@ def config( conn_health_checks: bool = False, disable_server_side_cursors: bool = False, ssl_require: bool = False, - test_options: Optional[Dict] = None, + test_options: Optional[Dict[str, Any]] = None, ) -> DBConfig: """Returns configured DATABASE dictionary from DATABASE_URL.""" s = os.environ.get(env, default) @@ -101,7 +101,7 @@ def parse( conn_health_checks: bool = False, disable_server_side_cursors: bool = False, ssl_require: bool = False, - test_options: Optional[dict] = None, + test_options: Optional[Dict[str, Any]] = None, ) -> DBConfig: """Parses a database URL.""" if url == "sqlite://:memory:": diff --git a/pyproject.toml b/pyproject.toml index 721375d..fc6ed1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,3 +6,6 @@ show_error_codes=true disallow_untyped_defs=true disallow_untyped_calls=true warn_redundant_casts=true + +[tool.pyright] +typeCheckingMode = "strict" diff --git a/requirements.txt b/requirements.txt index 3c036d6..7ae9a96 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ coverage mypy +pyright diff --git a/setup.py b/setup.py index 5d0f474..c69e8fa 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from pathlib import Path -from setuptools import setup +from setuptools import setup # pyright: ignore[reportUnknownVariableType] readme = Path("README.rst").read_text() diff --git a/tests/test_dj_database_url.py b/tests/test_dj_database_url.py index 6e46e27..f436ac8 100644 --- a/tests/test_dj_database_url.py +++ b/tests/test_dj_database_url.py @@ -1,3 +1,5 @@ +# pyright: reportTypedDictNotRequiredAccess=false + import os import unittest from unittest import mock