Skip to content

Conversation

@cbornet
Copy link
Collaborator

@cbornet cbornet commented Aug 22, 2025

No description provided.

Copy link

Copilot AI left a 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
Copy link

Copilot AI Aug 22, 2025

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.

Suggested change
yield
return self.result

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

@cbornet cbornet Aug 22, 2025

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
Copy link
Collaborator

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)

Copy link
Collaborator

@hemidactylus hemidactylus Aug 25, 2025

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 ...)

Copy link
Collaborator Author

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

Copy link
Collaborator

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?)

Copy link
Collaborator

@hemidactylus hemidactylus left a 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)

@hemidactylus hemidactylus merged commit a88fd37 into main Aug 25, 2025
14 of 16 checks passed
@hemidactylus hemidactylus deleted the strict-mypy branch August 25, 2025 15:09
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.

3 participants