forked from aio-libs/aiokafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add black and isort as formatting utility for the project. Start mypy…
… support. (aio-libs#638) * Refactored util.py and structs.py to pass mypy, format using blake and isort. Having automatic code formatting helps with consistent styling across the project, thus want to encorporate it part after part. * Add config.cfg and stubs for Kafka library * Flake should apply for the whole project, not only for formatted areas * Fix tests * Added dataclasses and async generator support for older python's
- Loading branch information
1 parent
5c12f57
commit 84e2a98
Showing
97 changed files
with
3,230 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,52 @@ | ||
import collections | ||
from dataclasses import dataclass | ||
from typing import Generic, NamedTuple, Optional, Sequence, Tuple, TypeVar | ||
|
||
from kafka.structs import ( | ||
OffsetAndMetadata, TopicPartition, BrokerMetadata, PartitionMetadata | ||
BrokerMetadata, | ||
OffsetAndMetadata, | ||
PartitionMetadata, | ||
TopicPartition, | ||
) | ||
|
||
|
||
__all__ = [ | ||
"OffsetAndMetadata", "TopicPartition", "RecordMetadata", "ConsumerRecord", | ||
"BrokerMetadata", "PartitionMetadata" | ||
"OffsetAndMetadata", | ||
"TopicPartition", | ||
"RecordMetadata", | ||
"ConsumerRecord", | ||
"BrokerMetadata", | ||
"PartitionMetadata", | ||
] | ||
|
||
RecordMetadata = collections.namedtuple( | ||
'RecordMetadata', ['topic', 'partition', 'topic_partition', 'offset', | ||
'timestamp', 'timestamp_type']) | ||
|
||
ConsumerRecord = collections.namedtuple( | ||
"ConsumerRecord", ["topic", "partition", "offset", "timestamp", | ||
"timestamp_type", "key", "value", "checksum", | ||
"serialized_key_size", "serialized_value_size", | ||
"headers"]) | ||
class RecordMetadata(NamedTuple): | ||
topic: str | ||
partition: int | ||
topic_partition: TopicPartition | ||
offset: int | ||
timestamp: Optional[int] # Timestamp in millis, None for older Brokers | ||
timestamp_type: int | ||
|
||
|
||
KT = TypeVar("KT") | ||
VT = TypeVar("VT") | ||
|
||
|
||
@dataclass | ||
class ConsumerRecord(Generic[KT, VT]): | ||
topic: str | ||
partition: int | ||
offset: int | ||
timestamp: int | ||
timestamp_type: int | ||
key: Optional[KT] | ||
value: Optional[VT] | ||
checksum: int | ||
serialized_key_size: int | ||
serialized_value_size: int | ||
headers: Sequence[Tuple[str, bytes]] | ||
|
||
|
||
OffsetAndTimestamp = collections.namedtuple( | ||
"OffsetAndTimestamp", ["offset", "timestamp"]) | ||
class OffsetAndTimestamp(NamedTuple): | ||
offset: int | ||
timestamp: Optional[int] # Only None if used with old broker version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
-r requirements-cython.txt | ||
flake8==3.8.3 | ||
black==19.10b0 | ||
mypy==0.782 | ||
isort==4.3.21 | ||
pytest==5.4.3 | ||
pytest-cov==2.10.0 | ||
pytest-asyncio==0.12.0 | ||
docker==4.2.1 | ||
lz4==3.1.0 | ||
xxhash==1.4.3 | ||
python-snappy==0.5.4 | ||
docutils==0.16 | ||
Pygments==2.6.1 | ||
gssapi==1.6.2 # pyup: <= 1.6.2 # For some reason 1.6.5 does not install with py35 | ||
dataclasses==0.5; python_version<"3.7" | ||
async_generator==1.10; python_version<"3.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
-r requirements-cython.txt | ||
flake8==3.8.3 | ||
black==19.10b0 | ||
mypy==0.782 | ||
isort==4.3.21 | ||
pytest==5.4.3 | ||
pytest-cov==2.10.0 | ||
pytest-asyncio==0.12.0 | ||
docker==4.2.1 | ||
lz4==3.1.0 | ||
xxhash==1.4.3 | ||
python-snappy==0.5.4 | ||
dataclasses==0.5; python_version<"3.7" | ||
async_generator==1.10; python_version<"3.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
exclude = | ||
.git | ||
venv | ||
__pycache__ | ||
.tox | ||
|
||
[isort] | ||
line_length=88 | ||
include_trailing_comma=True | ||
multi_line_output=3 | ||
force_grid_wrap=0 | ||
combine_as_imports=True | ||
lines_after_imports=2 | ||
known_standard_library=dataclasses | ||
known_first_party=aiokafka,kafka | ||
known_third_party=pytest | ||
|
||
[mypy] | ||
check_untyped_defs = True | ||
disallow_any_generics = True | ||
disallow_untyped_defs = True | ||
follow_imports = silent | ||
strict_optional = True | ||
warn_redundant_casts = True | ||
warn_unused_ignores = True | ||
warn_unused_configs = True | ||
mypy_path=stubs | ||
|
||
[mypy-pytest] | ||
ignore_missing_imports = True | ||
|
||
[mypy-Cython] | ||
ignore_missing_imports = True | ||
|
||
[mypy-kafka.*] | ||
warn_no_return = False | ||
disallow_untyped_defs = False | ||
|
||
[mypy-kafka.vendor.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-aiokafka.*] | ||
ignore_missing_imports = True | ||
|
||
[mypy-aiokafka.util] | ||
ignore_missing_imports = False |
Oops, something went wrong.