Skip to content

Fix Python 3.9 compatibility by adding annotations future import#156

Closed
talgalili wants to merge 1 commit intofacebookresearch:mainfrom
talgalili:export-D87538672
Closed

Fix Python 3.9 compatibility by adding annotations future import#156
talgalili wants to merge 1 commit intofacebookresearch:mainfrom
talgalili:export-D87538672

Conversation

@talgalili
Copy link
Contributor

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

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
@meta-codesync
Copy link

meta-codesync bot commented Nov 20, 2025

@talgalili has exported this pull request. If you are a Meta employee, you can view the originating Diff in D87538672.

@meta-codesync
Copy link

meta-codesync bot commented Nov 20, 2025

This pull request has been merged in 309bf25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants