PYTHON-6017 Consolidate QE enums into shared class - #3024
Conversation
There was a problem hiding this comment.
Pull request overview
This PR consolidates Queryable Encryption enums and related encryption helper utilities into a new shared module (pymongo/encryption_shared.py) to remove duplication between the synchronous and asynchronous encryption implementations.
Changes:
- Added
pymongo/encryption_shared.pyto hostAlgorithm,QueryType,RewrapManyDataKeyResult, and shared helpers like_wrap_encryption_errors/_create_mongocrypt_options. - Updated both async and sync encryption modules to import and re-export the moved public enums/types for backwards compatibility.
- Removed the now-duplicated local definitions from
pymongo/asynchronous/encryption.pyandpymongo/synchronous/encryption.py.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pymongo/encryption_shared.py | New shared home for QE enums and common encryption helper utilities. |
| pymongo/asynchronous/encryption.py | Switches to shared enums/helpers and deletes duplicated implementations. |
| pymongo/synchronous/encryption.py | Mirrors the async-side refactor by importing from the shared module (generated sync counterpart). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
| """ | ||
|
|
||
|
|
||
| def _create_mongocrypt_options(**kwargs: Any) -> MongoCryptOptions: |
There was a problem hiding this comment.
Do you want to grab _string_opts_kwarg() and _resolve_string_opts() too?
There was a problem hiding this comment.
_string_opts_kwarg calls inspect.signature(AsyncExplicitEncrypter), so it can't be moved out of the synchro'd file. _resolve_string_opts calls _string_opts_kwarg in turn so it also can't move.
|
|
||
| .. versionadded:: 4.2 | ||
| """ | ||
|
|
There was a problem hiding this comment.
We should mention used by both ClientEncryption and AsyncClientEncryption
|
|
||
| _HAVE_PYMONGOCRYPT = True | ||
| except ImportError: | ||
| _HAVE_PYMONGOCRYPT = False |
There was a problem hiding this comment.
_HAVE_PYMONGOCRYPT assigned but not used?
| @@ -0,0 +1,198 @@ | |||
| # Copyright 2019-present MongoDB, Inc. | |||
PYTHON-6017
Changes in this PR
Move QE enums and other shared encryption utilities into a new
pymongo/encryption_shared.pyfile.Test Plan
Existing test suite.
Checklist
Checklist for Author
[ ] Did you update the changelog (if necessary)?[ ] Is any followup work tracked in a JIRA ticket? If so, add link(s).Checklist for Reviewer