Skip to content

Commit a964194

Browse files
authored
Revert "Add type anotation to methods and functions (#779)" (#783)
This reverts commit 4c47abc.
1 parent 4c47abc commit a964194

File tree

13 files changed

+237
-276
lines changed

13 files changed

+237
-276
lines changed

push_notifications/api/rest_framework.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
from rest_framework.response import Response
44
from rest_framework.serializers import ModelSerializer, Serializer, ValidationError
55
from rest_framework.viewsets import ModelViewSet
6-
from typing import Any
7-
from push_notifications.fields import UNSIGNED_64BIT_INT_MAX_VALUE, hex_re
8-
from push_notifications.models import APNSDevice, GCMDevice, WebPushDevice, WNSDevice
9-
from push_notifications.settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS
10-
from django.db.models import QuerySet
6+
7+
from ..fields import UNSIGNED_64BIT_INT_MAX_VALUE, hex_re
8+
from ..models import APNSDevice, GCMDevice, WebPushDevice, WNSDevice
9+
from ..settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS
1110

1211

1312
# Fields
@@ -16,16 +15,16 @@ class HexIntegerField(IntegerField):
1615
Store an integer represented as a hex string of form "0x01".
1716
"""
1817

19-
def to_internal_value(self, data: str | int) -> int:
18+
def to_internal_value(self, data):
2019
# validate hex string and convert it to the unsigned
2120
# integer representation for internal use
2221
try:
23-
data = int(data, 16) if not isinstance(data, int) else data
22+
data = int(data, 16) if type(data) != int else data
2423
except ValueError:
2524
raise ValidationError("Device ID is not a valid hex number")
2625
return super().to_internal_value(data)
2726

28-
def to_representation(self, value: int) -> int:
27+
def to_representation(self, value):
2928
return value
3029

3130

@@ -46,7 +45,7 @@ class APNSDeviceSerializer(ModelSerializer):
4645
class Meta(DeviceSerializerMixin.Meta):
4746
model = APNSDevice
4847

49-
def validate_registration_id(self, value: str) -> str:
48+
def validate_registration_id(self, value):
5049

5150
# https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622958-application
5251
# As of 02/2023 APNS tokens (registration_id) "are of variable length. Do not hard-code their size."
@@ -57,7 +56,7 @@ def validate_registration_id(self, value: str) -> str:
5756

5857

5958
class UniqueRegistrationSerializerMixin(Serializer):
60-
def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
59+
def validate(self, attrs):
6160
devices = None
6261
primary_key = None
6362
request_method = None
@@ -104,7 +103,7 @@ class Meta(DeviceSerializerMixin.Meta):
104103
)
105104
extra_kwargs = {"id": {"read_only": False, "required": False}}
106105

107-
def validate_device_id(self, value: int) -> int:
106+
def validate_device_id(self, value):
108107
# device ids are 64 bit unsigned values
109108
if value > UNSIGNED_64BIT_INT_MAX_VALUE:
110109
raise ValidationError("Device ID is out of range")
@@ -127,7 +126,7 @@ class Meta(DeviceSerializerMixin.Meta):
127126

128127
# Permissions
129128
class IsOwner(permissions.BasePermission):
130-
def has_object_permission(self, request: Any, view: Any, obj: Any) -> bool:
129+
def has_object_permission(self, request, view, obj):
131130
# must be the owner to view the object
132131
return obj.user == request.user
133132

@@ -136,7 +135,7 @@ def has_object_permission(self, request: Any, view: Any, obj: Any) -> bool:
136135
class DeviceViewSetMixin:
137136
lookup_field = "registration_id"
138137

139-
def create(self, request: Any, *args: Any, **kwargs: Any) -> Response:
138+
def create(self, request, *args, **kwargs):
140139
serializer = None
141140
is_update = False
142141
if SETTINGS.get("UPDATE_ON_DUPLICATE_REG_ID") and self.lookup_field in request.data:
@@ -158,12 +157,12 @@ def create(self, request: Any, *args: Any, **kwargs: Any) -> Response:
158157
headers = self.get_success_headers(serializer.data)
159158
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
160159

161-
def perform_create(self, serializer: ModelSerializer) -> None:
160+
def perform_create(self, serializer):
162161
if self.request.user.is_authenticated:
163162
serializer.save(user=self.request.user)
164163
return super().perform_create(serializer)
165164

166-
def perform_update(self, serializer: ModelSerializer) -> None:
165+
def perform_update(self, serializer):
167166
if self.request.user.is_authenticated:
168167
serializer.save(user=self.request.user)
169168
return super().perform_update(serializer)
@@ -172,7 +171,7 @@ def perform_update(self, serializer: ModelSerializer) -> None:
172171
class AuthorizedMixin:
173172
permission_classes = (permissions.IsAuthenticated, IsOwner)
174173

175-
def get_queryset(self) -> QuerySet:
174+
def get_queryset(self):
176175
# filter all devices to only those belonging to the current user
177176
return self.queryset.filter(user=self.request.user)
178177

push_notifications/apns.py

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
from . import models
1515
from .conf import get_manager
1616
from .exceptions import APNSError, APNSUnsupportedPriority, APNSServerError
17-
from typing import Any, Callable
1817

1918

20-
def _apns_create_socket(creds=None, application_id=None) -> apns2_client.APNsClient:
19+
def _apns_create_socket(creds=None, application_id=None):
2120
if creds is None:
2221
if not get_manager().has_auth_token_creds(application_id):
2322
cert = get_manager().get_apns_certificate(application_id)
@@ -40,20 +39,9 @@ def _apns_create_socket(creds=None, application_id=None) -> apns2_client.APNsCli
4039

4140

4241
def _apns_prepare(
43-
token: str,
44-
alert: str | dict[str, Any] | None,
45-
application_id: str | None = None,
46-
badge: int | Callable | None = None,
47-
sound: str | None = None,
48-
category: str | None = None,
49-
content_available: bool = False,
50-
action_loc_key: str | None = None,
51-
loc_key: str | None = None,
52-
loc_args: str | None = [],
53-
extra: dict[str, Any] = {},
54-
mutable_content: bool = False,
55-
thread_id: str | None = None,
56-
url_args: list[str] | None = None) -> apns2_payload.Payload:
42+
token, alert, application_id=None, badge=None, sound=None, category=None,
43+
content_available=False, action_loc_key=None, loc_key=None, loc_args=[],
44+
extra={}, mutable_content=False, thread_id=None, url_args=None):
5745
if action_loc_key or loc_key or loc_args:
5846
apns2_alert = apns2_payload.PayloadAlert(
5947
body=alert if alert else {}, body_localized_key=loc_key,
@@ -71,13 +59,8 @@ def _apns_prepare(
7159

7260

7361
def _apns_send(
74-
registration_id: str | list[str],
75-
alert: str | dict[str, Any] | None,
76-
batch: bool = False,
77-
application_id: str | None = None,
78-
creds: apns2_credentials.Credentials | None = None,
79-
**kwargs: Any
80-
) -> dict[str, str] | None:
62+
registration_id, alert, batch=False, application_id=None, creds=None, **kwargs
63+
):
8164
client = _apns_create_socket(creds=creds, application_id=application_id)
8265

8366
notification_kwargs = {}
@@ -112,16 +95,9 @@ def _apns_send(
11295
get_manager().get_apns_topic(application_id=application_id),
11396
**notification_kwargs
11497
)
115-
return None
11698

11799

118-
def apns_send_message(
119-
registration_id: str,
120-
alert: str | dict[str, Any] | None,
121-
application_id: str | None = None,
122-
creds: apns2_credentials.Credentials | None = None,
123-
**kwargs: Any
124-
) -> None:
100+
def apns_send_message(registration_id, alert, application_id=None, creds=None, **kwargs):
125101
"""
126102
Sends an APNS notification to a single registration_id.
127103
This will send the notification as form data.
@@ -146,12 +122,8 @@ def apns_send_message(
146122

147123

148124
def apns_send_bulk_message(
149-
registration_ids: list[str],
150-
alert: str | dict[str, Any] | None,
151-
application_id: str | None = None,
152-
creds: apns2_credentials.Credentials | None = None,
153-
**kwargs: Any
154-
) -> dict[str, str]:
125+
registration_ids, alert, application_id=None, creds=None, **kwargs
126+
):
155127
"""
156128
Sends an APNS notification to one or more registration_ids.
157129
The registration_ids argument needs to be a list.

0 commit comments

Comments
 (0)