Skip to content

Commit

Permalink
Configure mypy with django-stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyNotHugo committed Oct 19, 2023
1 parent 01c5447 commit 2dc3ff9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]

Check warning on line 110 in payments/models.py

View check run for this annotation

Codecov / codecov/patch

payments/models.py#L110

Added line #L110 was not covered by tests
self.fraud_message = message
if commit:
self.save()
Expand Down
6 changes: 5 additions & 1 deletion payments/stripe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import warnings
from decimal import Decimal
from typing import TYPE_CHECKING

import stripe

Expand All @@ -15,6 +16,9 @@
from .forms import PaymentForm
from .providers import StripeProviderV3

if TYPE_CHECKING:
from django import forms

Check warning on line 20 in payments/stripe/__init__.py

View check run for this annotation

Codecov / codecov/patch

payments/stripe/__init__.py#L20

Added line #L20 was not covered by tests


class StripeProvider(BasicProvider):
"""Provider backend using `Stripe <https://stripe.com/>`_.
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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",
Expand Down
14 changes: 14 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2dc3ff9

Please sign in to comment.