You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by jr...@apache.org on 2025/08/26 19:09:57 UTC

(beam) branch master updated: Introduce Beartype Dependency for Type Checking (#35899)

This is an automated email from the ASF dual-hosted git repository.

jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 0589b14812e Introduce Beartype Dependency for Type Checking (#35899)
0589b14812e is described below

commit 0589b14812ec52bff9d20d3bfcd96da393b9ebdb
Author: Jack McCluskey <34...@users.noreply.github.com>
AuthorDate: Tue Aug 26 15:09:50 2025 -0400

    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
---
 sdks/python/apache_beam/typehints/typehints.py             | 13 +++++++++++--
 sdks/python/container/ml/py310/base_image_requirements.txt |  5 +++--
 sdks/python/container/ml/py311/base_image_requirements.txt |  5 +++--
 sdks/python/container/ml/py312/base_image_requirements.txt |  5 +++--
 sdks/python/container/ml/py39/base_image_requirements.txt  |  5 +++--
 sdks/python/container/py310/base_image_requirements.txt    |  5 +++--
 sdks/python/container/py311/base_image_requirements.txt    |  5 +++--
 sdks/python/container/py312/base_image_requirements.txt    |  5 +++--
 sdks/python/container/py313/base_image_requirements.txt    |  7 ++++---
 sdks/python/container/py39/base_image_requirements.txt     |  5 +++--
 sdks/python/setup.py                                       |  1 +
 11 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/sdks/python/apache_beam/typehints/typehints.py b/sdks/python/apache_beam/typehints/typehints.py
index 3b6afcc0a11..54eef4ee1a1 100644
--- a/sdks/python/apache_beam/typehints/typehints.py
+++ b/sdks/python/apache_beam/typehints/typehints.py
@@ -72,6 +72,9 @@ import types
 import typing
 from collections import abc
 
+from beartype.door import is_subhint
+from beartype.roar import BeartypeDoorException
+
 __all__ = [
     'Any',
     'Union',
@@ -1483,7 +1486,7 @@ _KNOWN_PRIMITIVE_TYPES.update({
 })
 
 
-def is_consistent_with(sub, base):
+def is_consistent_with(sub, base, use_beartype: bool = False) -> bool:
   """Checks whether sub a is consistent with base.
 
   This is according to the terminology of PEP 483/484.  This relationship is
@@ -1522,7 +1525,13 @@ def is_consistent_with(sub, base):
     # Cannot check unsupported parameterized generic which will cause issubclass
     # to fail with an exception.
     return False
-  return issubclass(sub, base)
+  if use_beartype:
+    try:
+      return is_subhint(sub, base)
+    except (BeartypeDoorException):
+      return False
+  else:
+    return issubclass(sub, base)
 
 
 def regex_consistency(sub, base) -> bool:
diff --git a/sdks/python/container/ml/py310/base_image_requirements.txt b/sdks/python/container/ml/py310/base_image_requirements.txt
index d5849d98a9e..ba2ee0d8534 100644
--- a/sdks/python/container/ml/py310/base_image_requirements.txt
+++ b/sdks/python/container/ml/py310/base_image_requirements.txt
@@ -33,6 +33,7 @@ astunparse==1.6.3
 async-timeout==5.0.1
 attrs==25.3.0
 backports.tarfile==1.2.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -191,7 +192,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -244,4 +245,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/container/ml/py311/base_image_requirements.txt b/sdks/python/container/ml/py311/base_image_requirements.txt
index 88b9d111496..15a4050ab0f 100644
--- a/sdks/python/container/ml/py311/base_image_requirements.txt
+++ b/sdks/python/container/ml/py311/base_image_requirements.txt
@@ -32,6 +32,7 @@ asn1crypto==1.5.1
 astunparse==1.6.3
 attrs==25.3.0
 backports.tarfile==1.2.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -189,7 +190,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -241,4 +242,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/container/ml/py312/base_image_requirements.txt b/sdks/python/container/ml/py312/base_image_requirements.txt
index e653b06f5ca..488e4e27f48 100644
--- a/sdks/python/container/ml/py312/base_image_requirements.txt
+++ b/sdks/python/container/ml/py312/base_image_requirements.txt
@@ -31,6 +31,7 @@ anyio==4.10.0
 asn1crypto==1.5.1
 astunparse==1.6.3
 attrs==25.3.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -188,7 +189,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -239,4 +240,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/container/ml/py39/base_image_requirements.txt b/sdks/python/container/ml/py39/base_image_requirements.txt
index d1630d2463b..3785f612a4a 100644
--- a/sdks/python/container/ml/py39/base_image_requirements.txt
+++ b/sdks/python/container/ml/py39/base_image_requirements.txt
@@ -33,6 +33,7 @@ astunparse==1.6.3
 async-timeout==5.0.1
 attrs==25.3.0
 backports.tarfile==1.2.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -191,7 +192,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -244,4 +245,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/container/py310/base_image_requirements.txt b/sdks/python/container/py310/base_image_requirements.txt
index fd4e424c6f5..3f4deee2971 100644
--- a/sdks/python/container/py310/base_image_requirements.txt
+++ b/sdks/python/container/py310/base_image_requirements.txt
@@ -31,6 +31,7 @@ asn1crypto==1.5.1
 async-timeout==5.0.1
 attrs==25.3.0
 backports.tarfile==1.2.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -155,7 +156,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -194,4 +195,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/container/py311/base_image_requirements.txt b/sdks/python/container/py311/base_image_requirements.txt
index a558a975c8a..d67181c22ba 100644
--- a/sdks/python/container/py311/base_image_requirements.txt
+++ b/sdks/python/container/py311/base_image_requirements.txt
@@ -30,6 +30,7 @@ anyio==4.10.0
 asn1crypto==1.5.1
 attrs==25.3.0
 backports.tarfile==1.2.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -153,7 +154,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -191,4 +192,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/container/py312/base_image_requirements.txt b/sdks/python/container/py312/base_image_requirements.txt
index f9b50f19aeb..35f29dbfa64 100644
--- a/sdks/python/container/py312/base_image_requirements.txt
+++ b/sdks/python/container/py312/base_image_requirements.txt
@@ -29,6 +29,7 @@ annotated-types==0.7.0
 anyio==4.10.0
 asn1crypto==1.5.1
 attrs==25.3.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -152,7 +153,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -190,4 +191,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/container/py313/base_image_requirements.txt b/sdks/python/container/py313/base_image_requirements.txt
index f9cd657b948..fd7516f4329 100644
--- a/sdks/python/container/py313/base_image_requirements.txt
+++ b/sdks/python/container/py313/base_image_requirements.txt
@@ -29,6 +29,7 @@ annotated-types==0.7.0
 anyio==4.10.0
 asn1crypto==1.5.1
 attrs==25.3.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -98,7 +99,7 @@ jeepney==0.9.0
 Jinja2==3.1.6
 joblib==1.5.1
 jsonpickle==3.4.2
-jsonschema==4.25.0
+jsonschema==4.25.1
 jsonschema-specifications==2025.4.1
 keyring==25.6.0
 keyrings.google-artifactregistry-auth==1.1.2
@@ -150,7 +151,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -187,4 +188,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/container/py39/base_image_requirements.txt b/sdks/python/container/py39/base_image_requirements.txt
index 9956cc3028c..423c6698041 100644
--- a/sdks/python/container/py39/base_image_requirements.txt
+++ b/sdks/python/container/py39/base_image_requirements.txt
@@ -31,6 +31,7 @@ asn1crypto==1.5.1
 async-timeout==5.0.1
 attrs==25.3.0
 backports.tarfile==1.2.0
+beartype==0.21.0
 beautifulsoup4==4.13.4
 bs4==0.0.2
 build==1.3.0
@@ -155,7 +156,7 @@ pytest-timeout==2.4.0
 pytest-xdist==3.8.0
 python-dateutil==2.9.0.post0
 python-dotenv==1.1.1
-python-tds==1.16.1
+python-tds==1.17.0
 pytz==2025.2
 PyYAML==6.0.2
 redis==5.3.1
@@ -194,4 +195,4 @@ wheel==0.45.1
 wrapt==1.17.3
 yarl==1.20.1
 zipp==3.23.0
-zstandard==0.23.0
+zstandard==0.24.0
diff --git a/sdks/python/setup.py b/sdks/python/setup.py
index 9702ba4746e..b8803417480 100644
--- a/sdks/python/setup.py
+++ b/sdks/python/setup.py
@@ -401,6 +401,7 @@ if __name__ == '__main__':
           'typing-extensions>=3.7.0',
           'zstandard>=0.18.0,<1',
           'pyyaml>=3.12,<7.0.0',
+          'beartype>=0.21.0,<0.22.0',
           # Dynamic dependencies must be specified in a separate list, otherwise
           # Dependabot won't be able to parse the main list. Any dynamic
           # dependencies will not receive updates from Dependabot.