Skip to content

Commit

Permalink
Merge pull request #4672 from mozilla/dependabot/pip/typing-stubs-fb7…
Browse files Browse the repository at this point in the history
…bf05f94

Bump the typing-stubs group with 2 updates
  • Loading branch information
jwhitlock authored May 6, 2024
2 parents 4f7fd20 + 91f9f1e commit 3336a5b
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
)

logger = logging.getLogger("events")
INTROSPECT_TOKEN_URL = (
"%s/introspect" % settings.SOCIALACCOUNT_PROVIDERS["fxa"]["OAUTH_ENDPOINT"]
INTROSPECT_TOKEN_URL = "{}/introspect".format(
settings.SOCIALACCOUNT_PROVIDERS["fxa"]["OAUTH_ENDPOINT"]
)


Expand Down
8 changes: 5 additions & 3 deletions api/serializers/phones.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from rest_framework import serializers

from phones.models import InboundContact, RealPhone, RelayNumber
Expand Down Expand Up @@ -104,7 +106,7 @@ class TwilioInboundSmsSerializer(serializers.Serializer):
from_ = serializers.CharField()
to = serializers.CharField()

def __init__(self, *args, **kwargs) -> None:
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
# Change to reserved keyword "from"
self.fields["from"] = self.fields.pop("from_")
Expand All @@ -116,7 +118,7 @@ class TwilioMessagesSerializer(serializers.Serializer):
date_sent = serializers.CharField()
body = serializers.CharField()

def __init__(self, *args, **kwargs) -> None:
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
# Change to reserved keyword "from"
self.fields["from"] = self.fields.pop("from_")
Expand Down Expand Up @@ -156,7 +158,7 @@ class IqInboundSmsSerializer(serializers.Serializer):
from_ = serializers.CharField()
to = serializers.CharField()

def __init__(self, *args, **kwargs) -> None:
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
# Change to reserved keyword "from"
self.fields["from"] = self.fields.pop("from_")
Expand Down
3 changes: 2 additions & 1 deletion api/tests/emails_views_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch

from django.contrib.auth.models import User
from django.test import Client
from django.urls import reverse
from django.utils import timezone

Expand Down Expand Up @@ -731,7 +732,7 @@ def test_delete_randomaddress(
assert event == expected_event


def test_first_forwarded_email_unauth(client) -> None:
def test_first_forwarded_email_unauth(client: Client) -> None:
response = client.post("/api/v1/first-forwarded-email/")
assert response.status_code == 401
assert response.json() == {"detail": str(NotAuthenticated())}
Expand Down
9 changes: 5 additions & 4 deletions emails/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.core.exceptions import BadRequest
from django.core.validators import MinLengthValidator
from django.db import models, transaction
from django.db.models.base import ModelBase
from django.db.models.query import QuerySet
from django.dispatch import receiver
from django.utils.translation.trans_real import (
Expand Down Expand Up @@ -137,11 +138,11 @@ class Profile(models.Model):
last_engagement = models.DateTimeField(blank=True, null=True, db_index=True)

def __str__(self):
return "%s Profile" % self.user
return f"{self.user} Profile"

def save(
self,
force_insert: bool = False,
force_insert: bool | tuple[ModelBase, ...] = False,
force_update: bool = False,
using: str | None = None,
update_fields: Iterable[str] | None = None,
Expand Down Expand Up @@ -791,7 +792,7 @@ def delete(self, *args, **kwargs):

def save(
self,
force_insert: bool = False,
force_insert: bool | tuple[ModelBase, ...] = False,
force_update: bool = False,
using: str | None = None,
update_fields: Iterable[str] | None = None,
Expand Down Expand Up @@ -935,7 +936,7 @@ def __str__(self):

def save(
self,
force_insert: bool = False,
force_insert: bool | tuple[ModelBase, ...] = False,
force_update: bool = False,
using: str | None = None,
update_fields: Iterable[str] | None = None,
Expand Down
2 changes: 1 addition & 1 deletion emails/tests/models_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ def test_make_domain_address_makes_different_addresses(self):
# not been fixed yet
for i in range(5):
domain_address = DomainAddress.make_domain_address(
self.user_profile, "test-different-%s" % i
self.user_profile, f"test-different-{i}"
)
assert domain_address.first_emailed_at is None
domain_addresses = DomainAddress.objects.filter(user=self.user).values_list(
Expand Down
2 changes: 1 addition & 1 deletion emails/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def get_reply_to_address(premium: bool = True) -> str:
"""Return the address that relays replies."""
if premium:
_, reply_to_address = parseaddr(
"replies@%s" % get_domains_from_settings().get("RELAY_FIREFOX_DOMAIN")
"replies@{}".format(get_domains_from_settings().get("RELAY_FIREFOX_DOMAIN"))
)
else:
_, reply_to_address = parseaddr(settings.RELAY_FROM_ADDRESS)
Expand Down
10 changes: 6 additions & 4 deletions emails/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,10 @@ def _sns_notification(json_body):
},
)
return HttpResponse(
"Received SNS notification for unsupported Type: %s"
% html.escape(shlex.quote(notification_type)),
(
"Received SNS notification for unsupported Type: "
f"{html.escape(shlex.quote(notification_type))}"
),
status=400,
)
response = _sns_message(message_json)
Expand Down Expand Up @@ -641,7 +643,7 @@ def _handle_received(message_json: AWS_SNSMessageJSON) -> HttpResponse:
bounce_paused, bounce_type = user_profile.check_bounce_pause()
if bounce_paused:
_record_receipt_verdicts(receipt, "user_bounce_paused")
incr_if_enabled("email_suppressed_for_%s_bounce" % bounce_type, 1)
incr_if_enabled(f"email_suppressed_for_{bounce_type}_bounce", 1)
reason: Literal["soft_bounce_pause", "hard_bounce_pause"] = (
"soft_bounce_pause" if bounce_type == "soft" else "hard_bounce_pause"
)
Expand Down Expand Up @@ -814,7 +816,7 @@ def _handle_received(message_json: AWS_SNSMessageJSON) -> HttpResponse:


def _get_verdict(receipt, verdict_type):
return receipt["%sVerdict" % verdict_type]["status"]
return receipt[f"{verdict_type}Verdict"]["status"]


def _check_email_from_list(headers):
Expand Down
8 changes: 4 additions & 4 deletions phones/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def suggested_numbers(user):
# TODO: can we make multiple pattern searches in a single Twilio API request
same_prefix_options = []
# look for numbers with same area code and 3-number prefix
contains = "%s****" % real_num[:8] if real_num else ""
contains = f"{real_num[:8]}****" if real_num else ""
twilio_nums = avail_nums.local.list(contains=contains, limit=10)
same_prefix_options.extend(convert_twilio_numbers_to_dict(twilio_nums))

Expand All @@ -459,17 +459,17 @@ def suggested_numbers(user):
same_prefix_options.extend(convert_twilio_numbers_to_dict(twilio_nums))

# look for numbers with same area code and 1-number prefix
contains = "%s******" % real_num[:6] if real_num else ""
contains = f"{real_num[:6]}******" if real_num else ""
twilio_nums = avail_nums.local.list(contains=contains, limit=10)
same_prefix_options.extend(convert_twilio_numbers_to_dict(twilio_nums))

# look for same number in other area codes
contains = "+1***%s" % real_num[5:] if real_num else ""
contains = f"+1***{real_num[5:]}" if real_num else ""
twilio_nums = avail_nums.local.list(contains=contains, limit=10)
other_areas_options = convert_twilio_numbers_to_dict(twilio_nums)

# look for any numbers in the area code
contains = "%s*******" % real_num[:5] if real_num else ""
contains = f"{real_num[:5]}*******" if real_num else ""
twilio_nums = avail_nums.local.list(contains=contains, limit=10)
same_area_options = convert_twilio_numbers_to_dict(twilio_nums)

Expand Down
2 changes: 1 addition & 1 deletion privaterelay/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def ready(self) -> None:
@cached_property
def fxa_verifying_keys(self) -> list[dict[str, Any]]:
resp = requests.get(
"%s/jwks" % settings.SOCIALACCOUNT_PROVIDERS["fxa"]["OAUTH_ENDPOINT"]
"{}/jwks".format(settings.SOCIALACCOUNT_PROVIDERS["fxa"]["OAUTH_ENDPOINT"])
)
if resp.status_code == 200:
keys: list[dict[str, Any]] = resp.json()["keys"]
Expand Down
2 changes: 1 addition & 1 deletion privaterelay/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def _get_initial_middleware() -> list[str]:

DATABASES = {
"default": dj_database_url.config(
default="sqlite:///%s" % os.path.join(BASE_DIR, "db.sqlite3")
default="sqlite:///{}".format(os.path.join(BASE_DIR, "db.sqlite3"))
)
}
# Optionally set a test database name.
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ extend-safe-fixes = [
# E712 Avoid equality comparisons to True / False
# Changes '== True' to 'is True'
"E712",
# UP031 Use format specifiers instead of percent format
"UP031",
]

[tool.ruff.lint.isort]
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ ruff==0.4.3
# type hinting
boto3-stubs==1.34.98
botocore-stubs==1.34.94
django-stubs==4.2.6
djangorestframework-stubs==3.14.4
django-stubs==5.0.0
djangorestframework-stubs==3.15.0
mypy-boto3-ses==1.34.0
mypy==1.10.0
types-pyOpenSSL==24.1.0.20240425
Expand Down

0 comments on commit 3336a5b

Please sign in to comment.