Skip to content

Commit ddc5d6a

Browse files
richdawe-cioclaude
andcommitted
Fix pylint errors: missing __init__.py, import ordering, exception handling
Add customerio/__init__.py so pylint can resolve the package hierarchy. Fix raise-missing-from, return-in-finally, and import ordering warnings. Fix RuntimeError formatting bug where %-placeholders were not interpolated. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent de0ee97 commit ddc5d6a

5 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎customerio/__init__.py‎

Whitespace-only changes.

‎customerio/analytics/client.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
from datetime import datetime
2-
from uuid import uuid4
3-
import logging
4-
import numbers
51
import atexit
62
import json
3+
import logging
4+
import numbers
5+
import queue
6+
from datetime import datetime
7+
from uuid import uuid4
78

89
from dateutil.tz import tzutc
910

10-
from customerio.analytics.utils import guess_timezone, clean
1111
from customerio.analytics.consumer import Consumer, MAX_MSG_SIZE
1212
from customerio.analytics.request import post, DatetimeSerializer
13+
from customerio.analytics.utils import guess_timezone, clean
1314
from customerio.analytics.version import VERSION
1415

15-
import queue
16-
1716
ID_TYPES = (numbers.Number, str)
1817

1918

@@ -269,7 +268,9 @@ def _enqueue(self, msg):
269268
# Check message size.
270269
msg_size = len(json.dumps(msg, cls=DatetimeSerializer).encode())
271270
if msg_size > MAX_MSG_SIZE:
272-
raise RuntimeError('Message exceeds %skb limit. (%s)', str(int(MAX_MSG_SIZE / 1024)), str(msg))
271+
raise RuntimeError(
272+
'Message exceeds %dkb limit. (%s)' % (MAX_MSG_SIZE // 1024, msg)
273+
)
273274

274275
# if send is False, return msg as if it was successfully queued
275276
if not self.send:

‎customerio/analytics/consumer.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import json
12
import logging
3+
from queue import Empty
24
from threading import Thread
3-
import monotonic
5+
46
import backoff
5-
import json
7+
import monotonic
68

79
from customerio.analytics.request import post, APIError, DatetimeSerializer
810

9-
from queue import Empty
10-
1111
MAX_MSG_SIZE = 32 << 10
1212

1313
# Our servers only accept batches less than 500KB. Here limit is set slightly
@@ -73,7 +73,7 @@ def upload(self):
7373
# mark items as acknowledged from queue
7474
for _ in batch:
7575
self.queue.task_done()
76-
return success
76+
return success
7777

7878
def next(self):
7979
"""Return the next batch of items to upload."""

‎customerio/analytics/request.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def post(write_key, host=None, gzip=False, timeout=15, proxies=None, **kwargs):
5656
payload = res.json()
5757
log.debug('received response: %s', payload)
5858
raise APIError(res.status_code, payload['code'], payload['message'])
59-
except ValueError:
60-
raise APIError(res.status_code, 'unknown', res.text)
59+
except ValueError as exc:
60+
raise APIError(res.status_code, 'unknown', res.text) from exc
6161

6262

6363
class APIError(Exception):

‎customerio/analytics/test/consumer.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import json
2+
import time
13
import unittest
4+
25
import mock
3-
import time
4-
import json
56

67
try:
78
from queue import Queue

0 commit comments

Comments
 (0)