Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add typing to aiokafka/conn.py #1021

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dimastbk
Copy link
Contributor

Changes

Fixes #

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> (e.g. 588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: Fix issue with non-ascii contents in doctest text files.

return self._port

def send(self, request, expect_response=True):
@overload
def send(self, request: Request[ResponseT]) -> Coroutine[None, None, ResponseT]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
@overload
def send(
self, request: Request[ResponseT], expect_response: Literal[False]
) -> Coroutine[None, None, None]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
aiokafka/conn.py Dismissed Show dismissed Hide dismissed
@overload
def _send_sasl_token(
self, payload: bytes, expect_response: Literal[False]
) -> Coroutine[None, None, None]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
aiokafka/conn.py Fixed Show fixed Hide fixed
@overload
def _send_sasl_token(
self, payload: bytes, expect_response: bool
) -> Union[Coroutine[None, None, None], Coroutine[None, None, bytes]]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
Makefile Show resolved Hide resolved
class CloseReason:
class Packet(NamedTuple):
correlation_id: int
request: Request[Response]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request is not generic

aiokafka/conn.py Outdated
if correlation_id is None: # Is a SASL packet, just pass it though
if not fut.done():
fut.set_result(resp)
if packet.correlation_id is None: # Is a SASL packet, just pass it though
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not need to define meaningless fields in SaslPacket, if we use isinstance here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class SaslPacket(NamedTuple):
    fut: asyncio.Future

without correation_id and request?

@overload
def _send_sasl_token(
self, payload: bytes, expect_response: Literal[True]
) -> Coroutine[None, None, bytes]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
self, payload: bytes, expect_response: Literal[True]
) -> Coroutine[None, None, bytes]: ...
@overload
def _send_sasl_token(self, payload: bytes) -> Coroutine[None, None, bytes]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
resp = cast(
Union[SaslAuthenticateResponse_v0, SaslAuthenticateResponse_v1],
resp,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required for mypy (but ok for pyright), problem only with union types (I think problem with https://github.com/python/mypy/labels/topic-join-v-union)

return ScramAuthenticator(
loop=self._loop,
sasl_plain_password=self._sasl_plain_password,
sasl_plain_username=self._sasl_plain_username,
sasl_mechanism=self._sasl_mechanism,
sasl_mechanism=self._sasl_mechanism, # type: ignore[arg-type]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required for mypy (but ok for pyright)

@@ -418,12 +507,13 @@ def _on_read_task_error(cls, self_ref, read_task):
self.close(reason=CloseReason.CONNECTION_BROKEN, exc=exc)

@staticmethod
def _idle_check(self_ref):
def _idle_check(self_ref: weakref.ReferenceType[AIOKafkaConnection]) -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be Self, but Self "isn't allowed in this context"

Copy link

codecov bot commented Jul 1, 2024

Codecov Report

Attention: Patch coverage is 96.57795% with 9 lines in your changes missing coverage. Please review.

Project coverage is 95.00%. Comparing base (b861a26) to head (2801b29).
Report is 2 commits behind head on master.

Files Patch % Lines
aiokafka/conn.py 93.18% 1 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1021      +/-   ##
==========================================
- Coverage   95.02%   95.00%   -0.02%     
==========================================
  Files         114      114              
  Lines       16970    17069      +99     
  Branches     2771     2779       +8     
==========================================
+ Hits        16125    16216      +91     
- Misses        497      498       +1     
- Partials      348      355       +7     
Flag Coverage Δ
cext 91.92% <96.57%> (-0.03%) ⬇️
integration 94.64% <96.19%> (-0.03%) ⬇️
purepy 94.48% <96.57%> (+0.02%) ⬆️
unit 53.00% <64.25%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dimastbk dimastbk marked this pull request as ready for review July 15, 2024 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants