fix(cdk): Resolve serpyco-rs issues with Optional type annotations in Python 3.10 #451
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes an issue with serpyco-rs and Optional type annotations in Python 3.10.
Root Cause
The issue occurs because Python 3.10 evaluates type annotations at runtime by default, which causes problems with serpyco-rs when analyzing Optional types. This has been confirmed to be related to generics inheritance and resolution in serpyco-rs (see ermakov-oleg/serpyco-rs#191 and ermakov-oleg/serpyco-rs#138).
Solution
Added
from __future__ import annotations
to key files with Optional type annotations:This makes type annotations be stored as strings rather than being evaluated at runtime, which resolves compatibility issues with serpyco-rs.
Related PR
This PR is paired with airbytehq/morph#63, which reverts a workaround in the morph repository.
Requested by Aaron (AJ) Steers (@aaronsteers).
Link to Devin run: https://app.devin.ai/sessions/8d30f3ebc188484a8d64ada18f6d04dc