Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure mypy with django-stubs #383

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"""
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 @@
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 @@
: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
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ braintree = ["braintree>=3.14.0"]
cybersource = ["suds-community>=0.6"]
dev = [
"coverage",
"django-stubs[compatible-mypy]",
"mock",
"pytest",
"pytest-cov",
"pytest-django",
"types-braintree",
"types-dj-database-url",
"types-requests",
"types-stripe",
"types-xmltodict",
]
docs = ["sphinx_rtd_theme"]
mercadopago = ["mercadopago>=2.0.0,<3.0.0"]
Expand All @@ -62,6 +68,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
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ python =
3.11: py311
3.12-dev: py312

[testenv:mypy]
setenv =
PYTHONPATH = {env:PATH}/testapp
extras = {[testenv]extras}
commands = mypy .

[gh-actions:env]
DJANGO =
3.2: dj32
Expand Down
Loading