-
Notifications
You must be signed in to change notification settings - Fork 12
Add strict mypy checking #139
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
Conversation
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.
Pull Request Overview
This PR adds strict mypy type checking to the AstraDB library by upgrading mypy configuration and fixing type-related issues found during the stricter checking. The changes enable more rigorous type safety while maintaining code functionality.
- Upgrade mypy version and enable strict mode with additional error checking
- Fix type annotations and add runtime type validation
- Resolve import path issues and remove unnecessary type ignore comments
Reviewed Changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Updates mypy version and enables strict type checking configuration |
langchain_astradb/cache.py |
Fixes type annotations for generators and improves sentinel object pattern |
langchain_astradb/utils/astradb.py |
Removes type ignore comments and refactors conditional assignment |
langchain_astradb/utils/vector_store_codecs.py |
Adds runtime type validation for document IDs |
tests/conftest.py |
Adds type validation for embedding input |
tests/unit_tests/test_callers.py |
Removes unnecessary type ignore comment |
tests/integration_tests/test_cache.py |
Fixes import path from relative to absolute |
tests/integration_tests/test_semantic_cache.py |
Fixes import path from relative to absolute |
tests/unit_tests/test_imports.py |
Adds test for the _reawaitable function |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if self.result is _unset: | ||
| self.result = yield from self.awaitable.__await__() | ||
|
|
||
| yield |
Copilot
AI
Aug 22, 2025
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.
This bare yield statement will cause the generator to yield None before returning the result, which breaks the awaitable protocol. The __await__ method should only yield from the original awaitable when the result is not cached.
| yield | |
| return self.result |
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.
If we remove the yield __await__ is not a generator anymore.
| enable_error_code = "deprecated" | ||
| warn_unreachable = true | ||
|
|
||
| # TODO: activate for 'strict' checking |
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.
Is this left to false intentionally? I suppose that would be even stricter (not that I'm advocating it, just a matter of checking this todo)
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.
I see there are about 100 generics without type parameter (some are Astrapy objects, some are dicts and such).
If there is a plan to slowly improve towards compliance in a later PR (as I would empathize with), then the comment here could be perhaps made clearer in that regard?
(to be honest, astrapy has introduced type parameters for tables/collections not too long ago ...)
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.
Yes, that’s a todo for later.
|
|
||
| # TODO: activate for 'strict' checking | ||
| disallow_any_generics = false | ||
|
|
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.
Also while we're at it, there are 2 newlines here (on purpose?)
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.
LGTM, thank you! Merging
(just out of caution I have seen all CI run green locally - going ahead right now)
No description provided.