-
Notifications
You must be signed in to change notification settings - Fork 249
Added type annotation to public classes. #1074
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
base: master
Are you sure you want to change the base?
Added type annotation to public classes. #1074
Conversation
|
||
from aiokafka import errors as Errors | ||
from aiokafka.client import CoordinationType |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
aiokafka.client
aiokafka.cluster
definition
import
aiokafka/abc.py
Outdated
@@ -103,7 +105,7 @@ class AbstractTokenProvider(abc.ABC): | |||
""" | |||
|
|||
@abc.abstractmethod | |||
async def token(self): | |||
async def token(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be -> str
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Based on the doc comment, I think you are right. I believe these are auto-generated though, so let me look to see if there are any concrete implementations, and what those are returning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
2b0a9b7
to
ce97a90
Compare
Changes
Adds type annotation to public classes, and
py.typed
so that client code can type check against this library.Fixes #980 (kind of)
Note that the issue in question seems to be more ambitious in that it aims to provide type information to the entire library:
This PR only aims to solve the latter.
Per providing type annotations, there are several ways to distribute type information:
This is the first option, and makes changes to
.py
files mostly just adding type annotations. If you prefer to go with the second option (which doesn't touch any.py
file), please have a look at #1075 instead.Details about this PR:
from __future__ import annotations
x | None
instead ofOptional[x]
x | y
instead ofUnion[x, y]
list[x]
/set[x]
/dict[x, y]
instead oftyping.List[x]
/typing.Set[x]
/typing.Dict[x, y]
list
, but varargs/default value istuple
None
Note that this is introducing a breaking change that may affect a small minority of users. The key/value serializer/deserializer functions no longer optional (with the identity function defined as the default parameter). This is so that the generic parameters
KT
/VT
can be inferred.This means that:
None
as their key/value serializer/deserializer function, there should be no change.However, if a client is explicitly passing in
None
, e.g., withAIOKafkaConsumer
:Or with
AIOKafkaProducer
:The type checker will reject it.

You can ignore the type checker though, and the application should work the same as before, as this PR does not change any runtime logic.
Checklist
CHANGES
folder<issue_id>.<type>
(e.g.588.bugfix
)issue_id
change it to the pr id after creating the PR.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.Fix issue with non-ascii contents in doctest text files.