Skip to content

Commit 135eb29

Browse files
committed
Resolve (most) linter complaints
1 parent 7aa8de6 commit 135eb29

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

adc/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
try:
2-
from importlib.metadata import version, PackageNotFoundError
2+
from importlib.metadata import PackageNotFoundError, version
33
except ImportError:
44
# NOTE: remove after dropping support for Python < 3.8
5-
from importlib_metadata import version, PackageNotFoundError
5+
from importlib_metadata import PackageNotFoundError, version
66

77
try:
88
__version__ = version("adc-streaming")

adc/consumer.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import dataclasses
22
import enum
33
import logging
4-
from datetime import datetime, timedelta
54
import threading
5+
from collections import defaultdict
6+
from datetime import datetime, timedelta
67
# Imports from typing are deprecated as of Python 3.9 but required for
78
# compatibility with earlier versions
8-
from typing import Dict, Iterable, Iterator, List, Optional, Set, Union, Collection
9-
from collections import defaultdict
9+
from typing import (Collection, Dict, Iterable, Iterator, List, Optional, Set,
10+
Union)
1011

1112
import confluent_kafka # type: ignore
1213
import confluent_kafka.admin # type: ignore
@@ -15,6 +16,7 @@
1516
from .errors import ErrorCallback, log_client_errors
1617
from .oidc import set_oauth_cb
1718

19+
1820
class LogicalOffset(enum.IntEnum):
1921
BEGINNING = confluent_kafka.OFFSET_BEGINNING
2022
EARLIEST = confluent_kafka.OFFSET_BEGINNING
@@ -26,6 +28,7 @@ class LogicalOffset(enum.IntEnum):
2628

2729
INVALID = confluent_kafka.OFFSET_INVALID
2830

31+
2932
class Consumer:
3033
conf: 'ConsumerConfig'
3134
_consumer: confluent_kafka.Consumer
@@ -99,14 +102,15 @@ def mark_done(self, msg: confluent_kafka.Message, asynchronous: bool = True):
99102
self._consumer.commit(msg, asynchronous=False)
100103

101104
def _offsets_for_position(self, partitions: Collection[confluent_kafka.TopicPartition],
102-
position: Union[datetime, LogicalOffset]) -> List[confluent_kafka.TopicPartition]:
105+
position: Union[datetime, LogicalOffset]) \
106+
-> List[confluent_kafka.TopicPartition]:
103107
if isinstance(position, datetime):
104108
offset = int(position.timestamp() * 1000)
105109
elif isinstance(position, LogicalOffset):
106110
offset = position
107111
else:
108112
raise TypeError("Only datetime objects and logical offsets supported")
109-
113+
110114
_partitions = [
111115
confluent_kafka.TopicPartition(topic=tp.topic, partition=tp.partition, offset=offset)
112116
for tp in partitions
@@ -248,6 +252,7 @@ def close(self):
248252
""" Close the consumer, ending its subscriptions. """
249253
self._consumer.close()
250254

255+
251256
# Used to be called ConsumerStartPosition, though this was confusing because
252257
# it only affects "auto.offset.reset" not the start position for a call to
253258
# consume.
@@ -258,10 +263,12 @@ class ConsumerDefaultPosition(enum.Enum):
258263
def __str__(self):
259264
return self.name.lower()
260265

266+
261267
# Alias to the old name
262268
# TODO: Remove alias on the next breaking release
263269
ConsumerStartPosition = ConsumerDefaultPosition
264270

271+
265272
@dataclasses.dataclass
266273
class ConsumerConfig:
267274
broker_urls: List[str]

adc/oidc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def set_oauth_cb(config):
1818

1919
from authlib.integrations.requests_client import OAuth2Session
2020
session = OAuth2Session(client_id, client_secret, scope=scope)
21-
21+
2222
def oauth_cb(*_, **__):
2323
token = session.fetch_token(
2424
token_endpoint, grant_type='client_credentials')

adc/producer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import abc
2-
from ast import comprehension
32
import dataclasses
43
import logging
54
from datetime import timedelta
65
from typing import Dict, List, Optional, Union
6+
77
try: # this will work only in python >= 3.8
88
from typing import Literal
99
except ImportError:
@@ -112,7 +112,8 @@ class ProducerConfig:
112112
# between attempts to reconnect to Kafka.
113113
reconnect_max_time: timedelta = timedelta(seconds=10)
114114

115-
compression_type: Optional[Union[Literal['gzip'], Literal['snappy'], Literal['lz4'], Literal['zstd']]] = None
115+
compression_type: Optional[Union[Literal['gzip'], Literal['snappy'],
116+
Literal['lz4'], Literal['zstd']]] = None
116117

117118
# maximum message size, before compression
118119
message_max_bytes: Optional[int] = None

0 commit comments

Comments
 (0)