diff --git a/.github/renovate.json5 b/.github/renovate.json5 index ace077435..f678f258f 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -63,6 +63,14 @@ '.kokoro/**', ], }, + { + description: 'Disable numpy updates for Python < 3.12 (numpy 2.x stubs break mypy there)', + matchPackageNames: [ + 'numpy', + ], + matchCurrentValue: '/^<2$/', + enabled: false, + }, ], customManagers: [ { diff --git a/packages/toolbox-adk/pyproject.toml b/packages/toolbox-adk/pyproject.toml index a89e8f13f..3d4e2ec2c 100644 --- a/packages/toolbox-adk/pyproject.toml +++ b/packages/toolbox-adk/pyproject.toml @@ -41,7 +41,9 @@ test = [ "pytest-asyncio==1.4.0", "pytest-cov==7.1.0", "pytest-mock==3.15.1", - "numpy<2", # Pinned to <2 to prevent mypy syntax errors on python 3.10 with numpy 2.x stubs, + # numpy 2.x stubs use the Python 3.12 `type` statement; mypy rejects them on older Pythons. + "numpy<2; python_version < '3.12'", + "numpy<3; python_version >= '3.12'", ] # Tells setuptools that packages are under the 'src' directory @@ -65,3 +67,10 @@ profile = "black" python_version = "3.10" warn_unused_configs = true disallow_incomplete_defs = true + +[[tool.mypy.overrides]] +# numpy 2.x stubs use the Python 3.12 `type` statement, which mypy rejects +# under python_version = "3.10". Skip analyzing numpy instead of pinning it. +module = ["numpy", "numpy.*"] +follow_imports = "skip" +follow_imports_for_stubs = true diff --git a/packages/toolbox-core/pyproject.toml b/packages/toolbox-core/pyproject.toml index 6e44e0a11..145070841 100644 --- a/packages/toolbox-core/pyproject.toml +++ b/packages/toolbox-core/pyproject.toml @@ -61,7 +61,9 @@ test = [ "google-cloud-storage==3.10.1", "aioresponses==0.7.8", "toolbox-core[telemetry]", - "numpy<2", # Pinned to <2 to prevent mypy syntax errors on python 3.10 with numpy 2.x stubs + # numpy 2.x stubs use the Python 3.12 `type` statement; mypy rejects them on older Pythons. + "numpy<2; python_version < '3.12'", + "numpy<3; python_version >= '3.12'", ] [build-system] requires = ["setuptools"] @@ -77,3 +79,10 @@ profile = "black" python_version = "3.10" warn_unused_configs = true disallow_incomplete_defs = true + +[[tool.mypy.overrides]] +# numpy 2.x stubs use the Python 3.12 `type` statement, which mypy rejects +# under python_version = "3.10". Skip analyzing numpy instead of pinning it. +module = ["numpy", "numpy.*"] +follow_imports = "skip" +follow_imports_for_stubs = true diff --git a/packages/toolbox-langchain/pyproject.toml b/packages/toolbox-langchain/pyproject.toml index 08b8df121..e5b374425 100644 --- a/packages/toolbox-langchain/pyproject.toml +++ b/packages/toolbox-langchain/pyproject.toml @@ -53,7 +53,9 @@ test = [ "Pillow==12.3.0; python_version >= '3.10'", "google-cloud-secret-manager==2.28.0", "google-cloud-storage==3.10.1", - "numpy<2", # Pinned to <2 to prevent mypy syntax errors on python 3.10 with numpy 2.x stubs + # numpy 2.x stubs use the Python 3.12 `type` statement; mypy rejects them on older Pythons. + "numpy<2; python_version < '3.12'", + "numpy<3; python_version >= '3.12'", ] [build-system] @@ -70,3 +72,10 @@ profile = "black" python_version = "3.10" warn_unused_configs = true disallow_incomplete_defs = true + +[[tool.mypy.overrides]] +# numpy 2.x stubs use the Python 3.12 `type` statement, which mypy rejects +# under python_version = "3.10". Skip analyzing numpy instead of pinning it. +module = ["numpy", "numpy.*"] +follow_imports = "skip" +follow_imports_for_stubs = true diff --git a/packages/toolbox-llamaindex/pyproject.toml b/packages/toolbox-llamaindex/pyproject.toml index c7df34736..1633248ae 100644 --- a/packages/toolbox-llamaindex/pyproject.toml +++ b/packages/toolbox-llamaindex/pyproject.toml @@ -53,7 +53,9 @@ test = [ "Pillow==12.3.0; python_version >= '3.10'", "google-cloud-secret-manager==2.28.0", "google-cloud-storage==3.10.1", - "numpy<2", # Pinned to <2 to prevent mypy syntax errors on python 3.10 with numpy 2.x stubs + # numpy 2.x stubs use the Python 3.12 `type` statement; mypy rejects them on older Pythons. + "numpy<2; python_version < '3.12'", + "numpy<3; python_version >= '3.12'", ] [build-system] @@ -70,3 +72,10 @@ profile = "black" python_version = "3.10" warn_unused_configs = true disallow_incomplete_defs = true + +[[tool.mypy.overrides]] +# numpy 2.x stubs use the Python 3.12 `type` statement, which mypy rejects +# under python_version = "3.10". Skip analyzing numpy instead of pinning it. +module = ["numpy", "numpy.*"] +follow_imports = "skip" +follow_imports_for_stubs = true