Fix Python 3.9 compatibility by adding annotations future import#156
Closed
talgalili wants to merge 1 commit intofacebookresearch:mainfrom
Closed
Fix Python 3.9 compatibility by adding annotations future import#156talgalili wants to merge 1 commit intofacebookresearch:mainfrom
talgalili wants to merge 1 commit intofacebookresearch:mainfrom
Conversation
Summary: The balance library was failing to import in Python 3.9 due to using the `|` union operator in type hints, which is only supported in Python 3.10+. The error manifested as: ``` TypeError: unsupported operand type(s) for |: 'types.GenericAlias' and 'type' ``` This occurred in the type annotation `dict[str, dict[str, str] | pd.Series]` in the `adjust_null` function. The fix adds `annotations` to the `from __future__ import` statement, which enables PEP 563 postponed evaluation of annotations. This causes all type hints to be stored as strings and evaluated lazily, making the Python 3.10+ union syntax compatible with Python 3.9. Differential Revision: D87538672
|
@talgalili has exported this pull request. If you are a Meta employee, you can view the originating Diff in D87538672. |
|
This pull request has been merged in 309bf25. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
The balance library was failing to import in Python 3.9 due to using the
|union operator in type hints, which is only supported in Python 3.10+. The error manifested as:This occurred in the type annotation
dict[str, dict[str, str] | pd.Series]in theadjust_nullfunction.The fix adds
annotationsto thefrom __future__ importstatement, which enables PEP 563 postponed evaluation of annotations. This causes all type hints to be stored as strings and evaluated lazily, making the Python 3.10+ union syntax compatible with Python 3.9.Differential Revision: D87538672