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

Turn on typechecking in our GitHub CI #14

Merged
merged 7 commits into from
Dec 8, 2023

Conversation

pniedzielski
Copy link
Collaborator

We already typecheck our examples, but we haven't been checking that the type annotations we include in our main source code are correct. This PR first turns on this type checking in our CI, and then fixes issues that the typechecker catches.

Closes: #6

@pniedzielski pniedzielski added bug Something isn't working enhancement New feature or request labels Dec 8, 2023
@pniedzielski pniedzielski requested a review from hallfox December 8, 2023 19:28
@pniedzielski pniedzielski requested a review from a team as a code owner December 8, 2023 19:28
We already typecheck the examples we bundle with the Python SDK.  This patch
turns on typechecking on the source code of the SDK as well, which is already
has type annotations.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
The `Dict[K,V]` type is invariant in both `K` and `V`, so if `V1` is a subtype
of `V2`, it isn’t the case that `Dict[K,V1]` is not a subtype of `Dict[K,V2]`.
This patch changes type annotations from the concrete type `Dict` to the
abstract base class `Mapping`, which is covariant in `V`, fixing some correct
uses in our package that are mistakenly marked as incorrect by type checkers.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
This function looks up the name of the Python script, so as to provide it to
the `NativeSession` as an identifier.  We guard the use of this name with a
`getattr` conditional, but the typechecker cannot determine that this forces it
to be non-`None`, so this patch adds an additional `assert` which never fires,
but which the typechecker can understand to silence an error.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
The type annotation for `on_message`’s `messages` argument has been incorrect,
and hasn’t matched the values that are being passed to it in tests.
`on_message` performs a conversion from the BlazingMQ wire protocol identifiers
for message property types, which are represented as `int`s, to the Python
SDK’s message property type enumeration, which are Python objects.  However,
the type annotation incorrectly documented that this conversion had already
taken place.  This patch updates the type annotation and makes the code that
does the conversion clearer.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
@pniedzielski pniedzielski merged commit 2e3f6d9 into bloomberg:main Dec 8, 2023
10 checks passed
@pniedzielski pniedzielski deleted the typechecking branch February 7, 2024 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add typechecking to the CI
2 participants