diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3edcb2679..0e3ef9ff7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,13 +18,6 @@ repos: - id: ruff args: [--fix, --exit-non-zero-on-fix] exclude: docs\/.* - - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.5.1" - hooks: - - id: mypy - additional_dependencies: - - types-requests - exclude: testapp - repo: https://github.com/psf/black rev: "23.9.1" hooks: diff --git a/payments/models.py b/payments/models.py index 922156bf3..52e7e76da 100644 --- a/payments/models.py +++ b/payments/models.py @@ -94,7 +94,7 @@ def change_status(self, status: PaymentStatus | str, message=""): """ from .signals import status_changed - self.status = status + self.status = status # type: ignore[assignment] self.message = message self.save(update_fields=["status", "message"]) status_changed.send(sender=type(self), instance=self) @@ -107,7 +107,7 @@ def change_fraud_status(self, status: PaymentStatus, message="", commit=True): status, ", ".join(available_statuses) ) ) - self.fraud_status = status + self.fraud_status = status # type: ignore[assignment] self.fraud_message = message if commit: self.save() diff --git a/payments/stripe/__init__.py b/payments/stripe/__init__.py index 05930f30e..fbe1c7699 100644 --- a/payments/stripe/__init__.py +++ b/payments/stripe/__init__.py @@ -3,6 +3,7 @@ import json import warnings from decimal import Decimal +from typing import TYPE_CHECKING import stripe @@ -15,6 +16,9 @@ from .forms import PaymentForm from .providers import StripeProviderV3 +if TYPE_CHECKING: + from django import forms + class StripeProvider(BasicProvider): """Provider backend using `Stripe `_. @@ -27,7 +31,7 @@ class StripeProvider(BasicProvider): :param image: Your logo. """ - form_class = ModalPaymentForm + form_class: type[forms.Form] = ModalPaymentForm def __init__(self, public_key, secret_key, image="", name="", **kwargs): stripe.api_key = secret_key diff --git a/pyproject.toml b/pyproject.toml index 365ccf469..40d5cd239 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,13 @@ exclude_lines = [ "if TYPE_CHECKING:", ] +[tool.mypy] +ignore_missing_imports = true +plugins = ["mypy_django_plugin.main"] + +[tool.django-stubs] +django_settings_module = "test_settings" + [tool.pytest.ini_options] addopts =[ "--cov=payments", diff --git a/tox.ini b/tox.ini index b800c95e6..537e17c3e 100644 --- a/tox.ini +++ b/tox.ini @@ -45,6 +45,20 @@ python = 3.11: py311 3.12-dev: py312 +[testenv:mypy] +setenv = + PYTHONPATH = {env:PATH}/testapp +deps = + {[testenv]deps} + django-stubs[compatible-mypy] + types-stripe + types-requests + types-braintree + types-xmltodict + types-dj-database-url +extras = {[testenv]extras} +commands = mypy . + [gh-actions:env] DJANGO = 2.2: dj22