Skip to content

Commit 309bf25

Browse files
talgalilimeta-codesync[bot]
authored andcommitted
Fix Python 3.9 compatibility by adding annotations future import (#156)
Summary: Pull Request resolved: #156 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 fbshipit-source-id: d6e92e47b9dce6c12b638daf9a5e75b43fa8e2a2
1 parent 66fb30b commit 309bf25

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

balance/weighting_methods/adjust_null.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
# pyre-strict
77

8-
from __future__ import absolute_import, division, print_function, unicode_literals
8+
from __future__ import (
9+
absolute_import,
10+
annotations,
11+
division,
12+
print_function,
13+
unicode_literals,
14+
)
915

1016
import logging
1117

0 commit comments

Comments
 (0)