Skip to content

Commit 0589b14

Browse files
authored
Introduce Beartype Dependency for Type Checking (#35899)
* Introduce Beartype Dependency for Type Checking * update container requirements * replace bare except case * swap to optional beartype usage
1 parent b723ba5 commit 0589b14

11 files changed

Lines changed: 40 additions & 21 deletions

sdks/python/apache_beam/typehints/typehints.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
import typing
7373
from collections import abc
7474

75+
from beartype.door import is_subhint
76+
from beartype.roar import BeartypeDoorException
77+
7578
__all__ = [
7679
'Any',
7780
'Union',
@@ -1483,7 +1486,7 @@ def normalize(x, none_as_type=False):
14831486
})
14841487

14851488

1486-
def is_consistent_with(sub, base):
1489+
def is_consistent_with(sub, base, use_beartype: bool = False) -> bool:
14871490
"""Checks whether sub a is consistent with base.
14881491
14891492
This is according to the terminology of PEP 483/484. This relationship is
@@ -1522,7 +1525,13 @@ def is_consistent_with(sub, base):
15221525
# Cannot check unsupported parameterized generic which will cause issubclass
15231526
# to fail with an exception.
15241527
return False
1525-
return issubclass(sub, base)
1528+
if use_beartype:
1529+
try:
1530+
return is_subhint(sub, base)
1531+
except (BeartypeDoorException):
1532+
return False
1533+
else:
1534+
return issubclass(sub, base)
15261535

15271536

15281537
def regex_consistency(sub, base) -> bool:

sdks/python/container/ml/py310/base_image_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ astunparse==1.6.3
3333
async-timeout==5.0.1
3434
attrs==25.3.0
3535
backports.tarfile==1.2.0
36+
beartype==0.21.0
3637
beautifulsoup4==4.13.4
3738
bs4==0.0.2
3839
build==1.3.0
@@ -191,7 +192,7 @@ pytest-timeout==2.4.0
191192
pytest-xdist==3.8.0
192193
python-dateutil==2.9.0.post0
193194
python-dotenv==1.1.1
194-
python-tds==1.16.1
195+
python-tds==1.17.0
195196
pytz==2025.2
196197
PyYAML==6.0.2
197198
redis==5.3.1
@@ -244,4 +245,4 @@ wheel==0.45.1
244245
wrapt==1.17.3
245246
yarl==1.20.1
246247
zipp==3.23.0
247-
zstandard==0.23.0
248+
zstandard==0.24.0

sdks/python/container/ml/py311/base_image_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ asn1crypto==1.5.1
3232
astunparse==1.6.3
3333
attrs==25.3.0
3434
backports.tarfile==1.2.0
35+
beartype==0.21.0
3536
beautifulsoup4==4.13.4
3637
bs4==0.0.2
3738
build==1.3.0
@@ -189,7 +190,7 @@ pytest-timeout==2.4.0
189190
pytest-xdist==3.8.0
190191
python-dateutil==2.9.0.post0
191192
python-dotenv==1.1.1
192-
python-tds==1.16.1
193+
python-tds==1.17.0
193194
pytz==2025.2
194195
PyYAML==6.0.2
195196
redis==5.3.1
@@ -241,4 +242,4 @@ wheel==0.45.1
241242
wrapt==1.17.3
242243
yarl==1.20.1
243244
zipp==3.23.0
244-
zstandard==0.23.0
245+
zstandard==0.24.0

sdks/python/container/ml/py312/base_image_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ anyio==4.10.0
3131
asn1crypto==1.5.1
3232
astunparse==1.6.3
3333
attrs==25.3.0
34+
beartype==0.21.0
3435
beautifulsoup4==4.13.4
3536
bs4==0.0.2
3637
build==1.3.0
@@ -188,7 +189,7 @@ pytest-timeout==2.4.0
188189
pytest-xdist==3.8.0
189190
python-dateutil==2.9.0.post0
190191
python-dotenv==1.1.1
191-
python-tds==1.16.1
192+
python-tds==1.17.0
192193
pytz==2025.2
193194
PyYAML==6.0.2
194195
redis==5.3.1
@@ -239,4 +240,4 @@ wheel==0.45.1
239240
wrapt==1.17.3
240241
yarl==1.20.1
241242
zipp==3.23.0
242-
zstandard==0.23.0
243+
zstandard==0.24.0

sdks/python/container/ml/py39/base_image_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ astunparse==1.6.3
3333
async-timeout==5.0.1
3434
attrs==25.3.0
3535
backports.tarfile==1.2.0
36+
beartype==0.21.0
3637
beautifulsoup4==4.13.4
3738
bs4==0.0.2
3839
build==1.3.0
@@ -191,7 +192,7 @@ pytest-timeout==2.4.0
191192
pytest-xdist==3.8.0
192193
python-dateutil==2.9.0.post0
193194
python-dotenv==1.1.1
194-
python-tds==1.16.1
195+
python-tds==1.17.0
195196
pytz==2025.2
196197
PyYAML==6.0.2
197198
redis==5.3.1
@@ -244,4 +245,4 @@ wheel==0.45.1
244245
wrapt==1.17.3
245246
yarl==1.20.1
246247
zipp==3.23.0
247-
zstandard==0.23.0
248+
zstandard==0.24.0

sdks/python/container/py310/base_image_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ asn1crypto==1.5.1
3131
async-timeout==5.0.1
3232
attrs==25.3.0
3333
backports.tarfile==1.2.0
34+
beartype==0.21.0
3435
beautifulsoup4==4.13.4
3536
bs4==0.0.2
3637
build==1.3.0
@@ -155,7 +156,7 @@ pytest-timeout==2.4.0
155156
pytest-xdist==3.8.0
156157
python-dateutil==2.9.0.post0
157158
python-dotenv==1.1.1
158-
python-tds==1.16.1
159+
python-tds==1.17.0
159160
pytz==2025.2
160161
PyYAML==6.0.2
161162
redis==5.3.1
@@ -194,4 +195,4 @@ wheel==0.45.1
194195
wrapt==1.17.3
195196
yarl==1.20.1
196197
zipp==3.23.0
197-
zstandard==0.23.0
198+
zstandard==0.24.0

sdks/python/container/py311/base_image_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ anyio==4.10.0
3030
asn1crypto==1.5.1
3131
attrs==25.3.0
3232
backports.tarfile==1.2.0
33+
beartype==0.21.0
3334
beautifulsoup4==4.13.4
3435
bs4==0.0.2
3536
build==1.3.0
@@ -153,7 +154,7 @@ pytest-timeout==2.4.0
153154
pytest-xdist==3.8.0
154155
python-dateutil==2.9.0.post0
155156
python-dotenv==1.1.1
156-
python-tds==1.16.1
157+
python-tds==1.17.0
157158
pytz==2025.2
158159
PyYAML==6.0.2
159160
redis==5.3.1
@@ -191,4 +192,4 @@ wheel==0.45.1
191192
wrapt==1.17.3
192193
yarl==1.20.1
193194
zipp==3.23.0
194-
zstandard==0.23.0
195+
zstandard==0.24.0

sdks/python/container/py312/base_image_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ annotated-types==0.7.0
2929
anyio==4.10.0
3030
asn1crypto==1.5.1
3131
attrs==25.3.0
32+
beartype==0.21.0
3233
beautifulsoup4==4.13.4
3334
bs4==0.0.2
3435
build==1.3.0
@@ -152,7 +153,7 @@ pytest-timeout==2.4.0
152153
pytest-xdist==3.8.0
153154
python-dateutil==2.9.0.post0
154155
python-dotenv==1.1.1
155-
python-tds==1.16.1
156+
python-tds==1.17.0
156157
pytz==2025.2
157158
PyYAML==6.0.2
158159
redis==5.3.1
@@ -190,4 +191,4 @@ wheel==0.45.1
190191
wrapt==1.17.3
191192
yarl==1.20.1
192193
zipp==3.23.0
193-
zstandard==0.23.0
194+
zstandard==0.24.0

sdks/python/container/py313/base_image_requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ annotated-types==0.7.0
2929
anyio==4.10.0
3030
asn1crypto==1.5.1
3131
attrs==25.3.0
32+
beartype==0.21.0
3233
beautifulsoup4==4.13.4
3334
bs4==0.0.2
3435
build==1.3.0
@@ -98,7 +99,7 @@ jeepney==0.9.0
9899
Jinja2==3.1.6
99100
joblib==1.5.1
100101
jsonpickle==3.4.2
101-
jsonschema==4.25.0
102+
jsonschema==4.25.1
102103
jsonschema-specifications==2025.4.1
103104
keyring==25.6.0
104105
keyrings.google-artifactregistry-auth==1.1.2
@@ -150,7 +151,7 @@ pytest-timeout==2.4.0
150151
pytest-xdist==3.8.0
151152
python-dateutil==2.9.0.post0
152153
python-dotenv==1.1.1
153-
python-tds==1.16.1
154+
python-tds==1.17.0
154155
pytz==2025.2
155156
PyYAML==6.0.2
156157
redis==5.3.1
@@ -187,4 +188,4 @@ wheel==0.45.1
187188
wrapt==1.17.3
188189
yarl==1.20.1
189190
zipp==3.23.0
190-
zstandard==0.23.0
191+
zstandard==0.24.0

sdks/python/container/py39/base_image_requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ asn1crypto==1.5.1
3131
async-timeout==5.0.1
3232
attrs==25.3.0
3333
backports.tarfile==1.2.0
34+
beartype==0.21.0
3435
beautifulsoup4==4.13.4
3536
bs4==0.0.2
3637
build==1.3.0
@@ -155,7 +156,7 @@ pytest-timeout==2.4.0
155156
pytest-xdist==3.8.0
156157
python-dateutil==2.9.0.post0
157158
python-dotenv==1.1.1
158-
python-tds==1.16.1
159+
python-tds==1.17.0
159160
pytz==2025.2
160161
PyYAML==6.0.2
161162
redis==5.3.1
@@ -194,4 +195,4 @@ wheel==0.45.1
194195
wrapt==1.17.3
195196
yarl==1.20.1
196197
zipp==3.23.0
197-
zstandard==0.23.0
198+
zstandard==0.24.0

0 commit comments

Comments
 (0)