Skip to content

Tech debt: let HistoryEncoding work with string-based type annotations in addition to the normal type-based ones #3068

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

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

asnare
Copy link
Contributor

@asnare asnare commented Oct 24, 2024

Changes

This PR cherry-picks some changes from #3039 that updated the HistoryEncoder to work correctly with dataclasses that are declared with __future__.__annotations__ in effect.

When this annotation is in effect, python converts all type-hints during import/declaration into strings and then performs deferred resolution at a later stage. (This is why forward references work.) Unfortunately the dataclass mechanism captures field types prior to deferred resolution. This PR ensures that our type checking works anyway.

Linked issues

Cherry-picks from #3039.

Tests

  • updated unit tests

…dition to the normal class-based ones.

This is needed for correct functioning if a dataclass is declared in a __future__.__annotations__ context: here python converts all type hints to strings (at which point the dataclass metaclass captures them) prior to deferred resolution.
@asnare asnare added bug internal this pull request won't appear in release notes labels Oct 24, 2024
@asnare asnare self-assigned this Oct 24, 2024
@asnare asnare requested a review from a team as a code owner October 24, 2024 13:18
Copy link

✅ 6/6 passed, 15m15s total

Running from acceptance #7025

Copy link
Collaborator

@nfx nfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nfx nfx merged commit ece2a97 into main Oct 24, 2024
7 checks passed
@nfx nfx deleted the historical-encoder-str-annotations branch October 24, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal this pull request won't appear in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants