Skip to content

Commit cf3203b

Browse files
authored
Upgraded to pylint 2.x (#384)
* Removing Python 2 support * Upgraded to Pylint 2.x and fixed all linter errors for Python 3 * Downgrading to pylint 2.3 since 2.4 won't install on Python 3.4
1 parent 31d91d6 commit cf3203b

38 files changed

+272
-272
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ python:
99
jobs:
1010
include:
1111
- name: "Lint"
12-
python: "2.7"
12+
python: "3.7"
1313
script: ./lint.sh all
1414

1515
before_install:

firebase_admin/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ def initialize_app(credential=None, options=None, name=_DEFAULT_APP_NAME):
7777
'initialize_app() once. But if you do want to initialize multiple '
7878
'apps, pass a second argument to initialize_app() to give each app '
7979
'a unique name.'))
80-
else:
81-
raise ValueError((
82-
'Firebase app named "{0}" already exists. This means you called '
83-
'initialize_app() more than once with the same app name as the '
84-
'second argument. Make sure you provide a unique name every time '
85-
'you call initialize_app().').format(name))
80+
81+
raise ValueError((
82+
'Firebase app named "{0}" already exists. This means you called '
83+
'initialize_app() more than once with the same app name as the '
84+
'second argument. Make sure you provide a unique name every time '
85+
'you call initialize_app().').format(name))
8686

8787

8888
def delete_app(app):
@@ -106,11 +106,11 @@ def delete_app(app):
106106
raise ValueError(
107107
'The default Firebase app is not initialized. Make sure to initialize '
108108
'the default app by calling initialize_app().')
109-
else:
110-
raise ValueError(
111-
('Firebase app named "{0}" is not initialized. Make sure to initialize '
112-
'the app by calling initialize_app() with your app name as the '
113-
'second argument.').format(app.name))
109+
110+
raise ValueError(
111+
('Firebase app named "{0}" is not initialized. Make sure to initialize '
112+
'the app by calling initialize_app() with your app name as the '
113+
'second argument.').format(app.name))
114114

115115

116116
def get_app(name=_DEFAULT_APP_NAME):
@@ -137,14 +137,14 @@ def get_app(name=_DEFAULT_APP_NAME):
137137
raise ValueError(
138138
'The default Firebase app does not exist. Make sure to initialize '
139139
'the SDK by calling initialize_app().')
140-
else:
141-
raise ValueError(
142-
('Firebase app named "{0}" does not exist. Make sure to initialize '
143-
'the SDK by calling initialize_app() with your app name as the '
144-
'second argument.').format(name))
140+
141+
raise ValueError(
142+
('Firebase app named "{0}" does not exist. Make sure to initialize '
143+
'the SDK by calling initialize_app() with your app name as the '
144+
'second argument.').format(name))
145145

146146

147-
class _AppOptions(object):
147+
class _AppOptions:
148148
"""A collection of configuration options for an App."""
149149

150150
def __init__(self, options):
@@ -185,7 +185,7 @@ def _load_from_environment(self):
185185
return {k: v for k, v in json_data.items() if k in _CONFIG_VALID_KEYS}
186186

187187

188-
class App(object):
188+
class App:
189189
"""The entry point for Firebase Python SDK.
190190
191191
Represents a Firebase app, while holding the configuration and state

firebase_admin/_auth_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def validate_provider_id(provider_id, required=True):
103103
return provider_id
104104

105105
def validate_photo_url(photo_url, required=False):
106+
"""Parses and validates the given URL string."""
106107
if photo_url is None and not required:
107108
return None
108109
if not isinstance(photo_url, six.string_types) or not photo_url:
@@ -118,6 +119,7 @@ def validate_photo_url(photo_url, required=False):
118119
raise ValueError('Malformed photo URL: "{0}".'.format(photo_url))
119120

120121
def validate_timestamp(timestamp, label, required=False):
122+
"""Validates the given timestamp value. Timestamps must be positive integers."""
121123
if timestamp is None and not required:
122124
return None
123125
if isinstance(timestamp, bool):
@@ -181,7 +183,7 @@ def validate_custom_claims(custom_claims, required=False):
181183
if len(invalid_claims) > 1:
182184
joined = ', '.join(sorted(invalid_claims))
183185
raise ValueError('Claims "{0}" are reserved, and must not be set.'.format(joined))
184-
elif len(invalid_claims) == 1:
186+
if len(invalid_claims) == 1:
185187
raise ValueError(
186188
'Claim "{0}" is reserved, and must not be set.'.format(invalid_claims.pop()))
187189
return claims_str

firebase_admin/_http_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
raise_on_status=False, backoff_factor=0.5)
3333

3434

35-
class HttpClient(object):
35+
class HttpClient:
3636
"""Base HTTP client used to make HTTP calls.
3737
3838
HttpClient maintains an HTTP session, and handles request authentication and retries if

firebase_admin/_messaging_encoder.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import firebase_admin._messaging_utils as _messaging_utils
2626

2727

28-
class Message(object):
28+
class Message:
2929
"""A message that can be sent via Firebase Cloud Messaging.
3030
3131
Contains payload information as well as recipient information. In particular, the message must
@@ -61,7 +61,7 @@ def __str__(self):
6161
return json.dumps(self, cls=MessageEncoder, sort_keys=True)
6262

6363

64-
class MulticastMessage(object):
64+
class MulticastMessage:
6565
"""A message that can be sent to multiple tokens via Firebase Cloud Messaging.
6666
6767
Args:
@@ -88,7 +88,7 @@ def __init__(self, tokens, data=None, notification=None, android=None, webpush=N
8888
self.fcm_options = fcm_options
8989

9090

91-
class _Validators(object):
91+
class _Validators:
9292
"""A collection of data validation utilities.
9393
9494
Methods provided in this class raise ``ValueErrors`` if any validations fail.
@@ -102,8 +102,7 @@ def check_string(cls, label, value, non_empty=False):
102102
if not isinstance(value, six.string_types):
103103
if non_empty:
104104
raise ValueError('{0} must be a non-empty string.'.format(label))
105-
else:
106-
raise ValueError('{0} must be a string.'.format(label))
105+
raise ValueError('{0} must be a string.'.format(label))
107106
if non_empty and not value:
108107
raise ValueError('{0} must be a non-empty string.'.format(label))
109108
return value
@@ -647,6 +646,7 @@ def encode_notification(cls, notification):
647646

648647
@classmethod
649648
def sanitize_topic_name(cls, topic):
649+
"""Removes the /topics/ prefix from the topic name, if present."""
650650
if not topic:
651651
return None
652652
prefix = '/topics/'
@@ -657,20 +657,20 @@ def sanitize_topic_name(cls, topic):
657657
raise ValueError('Malformed topic name.')
658658
return topic
659659

660-
def default(self, obj): # pylint: disable=method-hidden
661-
if not isinstance(obj, Message):
662-
return json.JSONEncoder.default(self, obj)
660+
def default(self, o): # pylint: disable=method-hidden
661+
if not isinstance(o, Message):
662+
return json.JSONEncoder.default(self, o)
663663
result = {
664-
'android': MessageEncoder.encode_android(obj.android),
665-
'apns': MessageEncoder.encode_apns(obj.apns),
664+
'android': MessageEncoder.encode_android(o.android),
665+
'apns': MessageEncoder.encode_apns(o.apns),
666666
'condition': _Validators.check_string(
667-
'Message.condition', obj.condition, non_empty=True),
668-
'data': _Validators.check_string_dict('Message.data', obj.data),
669-
'notification': MessageEncoder.encode_notification(obj.notification),
670-
'token': _Validators.check_string('Message.token', obj.token, non_empty=True),
671-
'topic': _Validators.check_string('Message.topic', obj.topic, non_empty=True),
672-
'webpush': MessageEncoder.encode_webpush(obj.webpush),
673-
'fcm_options': MessageEncoder.encode_fcm_options(obj.fcm_options),
667+
'Message.condition', o.condition, non_empty=True),
668+
'data': _Validators.check_string_dict('Message.data', o.data),
669+
'notification': MessageEncoder.encode_notification(o.notification),
670+
'token': _Validators.check_string('Message.token', o.token, non_empty=True),
671+
'topic': _Validators.check_string('Message.topic', o.topic, non_empty=True),
672+
'webpush': MessageEncoder.encode_webpush(o.webpush),
673+
'fcm_options': MessageEncoder.encode_fcm_options(o.fcm_options),
674674
}
675675
result['topic'] = MessageEncoder.sanitize_topic_name(result.get('topic'))
676676
result = MessageEncoder.remove_null_values(result)

firebase_admin/_messaging_utils.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from firebase_admin import exceptions
1818

1919

20-
class Notification(object):
20+
class Notification:
2121
"""A notification that can be included in a message.
2222
2323
Args:
@@ -32,7 +32,7 @@ def __init__(self, title=None, body=None, image=None):
3232
self.image = image
3333

3434

35-
class AndroidConfig(object):
35+
class AndroidConfig:
3636
"""Android-specific options that can be included in a message.
3737
3838
Args:
@@ -62,7 +62,7 @@ def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_packag
6262
self.fcm_options = fcm_options
6363

6464

65-
class AndroidNotification(object):
65+
class AndroidNotification:
6666
"""Android-specific notification parameters.
6767
6868
Args:
@@ -178,7 +178,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag
178178
self.notification_count = notification_count
179179

180180

181-
class LightSettings(object):
181+
class LightSettings:
182182
"""Represents settings to control notification LED that can be included in a
183183
``messaging.AndroidNotification``.
184184
@@ -196,7 +196,7 @@ def __init__(self, color, light_on_duration_millis,
196196
self.light_off_duration_millis = light_off_duration_millis
197197

198198

199-
class AndroidFCMOptions(object):
199+
class AndroidFCMOptions:
200200
"""Options for features provided by the FCM SDK for Android.
201201
202202
Args:
@@ -208,7 +208,7 @@ def __init__(self, analytics_label=None):
208208
self.analytics_label = analytics_label
209209

210210

211-
class WebpushConfig(object):
211+
class WebpushConfig:
212212
"""Webpush-specific options that can be included in a message.
213213
214214
Args:
@@ -230,7 +230,7 @@ def __init__(self, headers=None, data=None, notification=None, fcm_options=None)
230230
self.fcm_options = fcm_options
231231

232232

233-
class WebpushNotificationAction(object):
233+
class WebpushNotificationAction:
234234
"""An action available to the users when the notification is presented.
235235
236236
Args:
@@ -245,7 +245,7 @@ def __init__(self, action, title, icon=None):
245245
self.icon = icon
246246

247247

248-
class WebpushNotification(object):
248+
class WebpushNotification:
249249
"""Webpush-specific notification parameters.
250250
251251
Refer to the `Notification Reference`_ for more information.
@@ -302,7 +302,7 @@ def __init__(self, title=None, body=None, icon=None, actions=None, badge=None, d
302302
self.custom_data = custom_data
303303

304304

305-
class WebpushFCMOptions(object):
305+
class WebpushFCMOptions:
306306
"""Options for features provided by the FCM SDK for Web.
307307
308308
Args:
@@ -314,7 +314,7 @@ def __init__(self, link=None):
314314
self.link = link
315315

316316

317-
class APNSConfig(object):
317+
class APNSConfig:
318318
"""APNS-specific options that can be included in a message.
319319
320320
Refer to `APNS Documentation`_ for more information.
@@ -335,7 +335,7 @@ def __init__(self, headers=None, payload=None, fcm_options=None):
335335
self.fcm_options = fcm_options
336336

337337

338-
class APNSPayload(object):
338+
class APNSPayload:
339339
"""Payload of an APNS message.
340340
341341
Args:
@@ -349,7 +349,7 @@ def __init__(self, aps, **kwargs):
349349
self.custom_data = kwargs
350350

351351

352-
class Aps(object):
352+
class Aps:
353353
"""Aps dictionary to be included in an APNS payload.
354354
355355
Args:
@@ -379,7 +379,7 @@ def __init__(self, alert=None, badge=None, sound=None, content_available=None, c
379379
self.custom_data = custom_data
380380

381381

382-
class CriticalSound(object):
382+
class CriticalSound:
383383
"""Critical alert sound configuration that can be included in ``messaging.Aps``.
384384
385385
Args:
@@ -398,7 +398,7 @@ def __init__(self, name, critical=None, volume=None):
398398
self.volume = volume
399399

400400

401-
class ApsAlert(object):
401+
class ApsAlert:
402402
"""An alert that can be included in ``messaging.Aps``.
403403
404404
Args:
@@ -437,7 +437,7 @@ def __init__(self, title=None, subtitle=None, body=None, loc_key=None, loc_args=
437437
self.custom_data = custom_data
438438

439439

440-
class APNSFCMOptions(object):
440+
class APNSFCMOptions:
441441
"""Options for features provided by the FCM SDK for iOS.
442442
443443
Args:
@@ -452,7 +452,7 @@ def __init__(self, analytics_label=None, image=None):
452452
self.image = image
453453

454454

455-
class FCMOptions(object):
455+
class FCMOptions:
456456
"""Options for features provided by SDK.
457457
458458
Args:

firebase_admin/_sseclient.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def rebuild_auth(self, prepared_request, response):
4040
pass
4141

4242

43-
class _EventBuffer(object):
43+
class _EventBuffer:
4444
"""A helper class for buffering and parsing raw SSE data."""
4545

4646
def __init__(self):
@@ -68,7 +68,7 @@ def buffer_string(self):
6868
return ''.join(self._buffer)
6969

7070

71-
class SSEClient(object):
71+
class SSEClient:
7272
"""SSE client implementation."""
7373

7474
def __init__(self, url, session, retry=3000, **kwargs):
@@ -140,7 +140,7 @@ def __next__(self):
140140
if event.data == 'credential is no longer valid':
141141
self._connect()
142142
return None
143-
elif event.data == 'null':
143+
if event.data == 'null':
144144
return None
145145

146146
# If the server requests a specific retry delay, we need to honor it.
@@ -157,7 +157,7 @@ def next(self):
157157
return self.__next__()
158158

159159

160-
class Event(object):
160+
class Event:
161161
"""Event represents the events fired by SSE."""
162162

163163
sse_line_pattern = re.compile('(?P<name>[^:]*):?( ?(?P<value>.*))?')
@@ -192,7 +192,7 @@ def parse(cls, raw):
192192
if name == '':
193193
# line began with a ":", so is a comment. Ignore
194194
continue
195-
elif name == 'data':
195+
if name == 'data':
196196
# If we already have some data, then join to it with a newline.
197197
# Else this is it.
198198
if event.data:

0 commit comments

Comments
 (0)