From 60d977aaa1b7c323c700c2305c76a8224acf6bed Mon Sep 17 00:00:00 2001 From: adrianrfreedman <5554371+adrianrfreedman@users.noreply.github.com> Date: Mon, 12 Oct 2026 21:48:50 +0300 Subject: [PATCH 1/3] fix(complexity_router): import regex internals from re on Python 3.11+ sre_constants and sre_parse were deprecated in Python 3.11 and removed in 3.15, so importing them breaks every `import litellm` on 3.15. Since 3.11 both modules only re-export re._constants and re._parser, so the opcodes are the same objects. Fixes #46060 --- litellm/router_strategy/complexity_router/config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/litellm/router_strategy/complexity_router/config.py b/litellm/router_strategy/complexity_router/config.py index 4a2c56daf00..1840dba3c85 100644 --- a/litellm/router_strategy/complexity_router/config.py +++ b/litellm/router_strategy/complexity_router/config.py @@ -7,7 +7,7 @@ All values are configurable via proxy config.yaml. import math import re -import warnings +import sys from collections.abc import Iterable, Mapping from dataclasses import dataclass from enum import Enum @@ -27,8 +27,12 @@ from pydantic import ( from litellm.types.llms.base import LiteLLMBaseModel -with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) +# Python 3.11 moved the regex parser into re._parser / re._constants; the top-level +# sre_parse / sre_constants shims were deprecated then and removed in Python 3.15. +if sys.version_info >= (3, 11): + from re import _constants as sre_constants + from re import _parser as sre_parse +else: import sre_constants import sre_parse From 4582e98692ad8335402eaeeb792ba656de20dbc3 Mon Sep 17 00:00:00 2001 From: adrianrfreedman <5554371+adrianrfreedman@users.noreply.github.com> Date: Mon, 12 Oct 2026 21:54:51 +0300 Subject: [PATCH 2/3] chore(complexity_router): drop the version guard comment AGENTS.md keeps comments out unless they explain complex business logic. The guard reads clearly on its own and the reason sits in the commit above. --- litellm/router_strategy/complexity_router/config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/litellm/router_strategy/complexity_router/config.py b/litellm/router_strategy/complexity_router/config.py index 1840dba3c85..45b22f87944 100644 --- a/litellm/router_strategy/complexity_router/config.py +++ b/litellm/router_strategy/complexity_router/config.py @@ -27,8 +27,6 @@ from pydantic import ( from litellm.types.llms.base import LiteLLMBaseModel -# Python 3.11 moved the regex parser into re._parser / re._constants; the top-level -# sre_parse / sre_constants shims were deprecated then and removed in Python 3.15. if sys.version_info >= (3, 11): from re import _constants as sre_constants from re import _parser as sre_parse From 64b186e292f0b7674765567f5feeb6125a102666 Mon Sep 17 00:00:00 2001 From: adrianrfreedman <5554371+adrianrfreedman@users.noreply.github.com> Date: Mon, 12 Oct 2026 22:07:28 +0300 Subject: [PATCH 3/3] fix(complexity_router): keep the typeshed stubs for the regex internals basedpyright has no stubs for re._constants or re._parser, so importing them directly added 22 unknown-type errors and broke the type gate. Point the type checker at sre_constants and sre_parse, which are still stubbed, and leave the runtime on re._* for 3.11 and up. --- litellm/router_strategy/complexity_router/config.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/litellm/router_strategy/complexity_router/config.py b/litellm/router_strategy/complexity_router/config.py index 45b22f87944..ec960a19f79 100644 --- a/litellm/router_strategy/complexity_router/config.py +++ b/litellm/router_strategy/complexity_router/config.py @@ -12,7 +12,7 @@ from collections.abc import Iterable, Mapping from dataclasses import dataclass from enum import Enum from types import MappingProxyType -from typing import Annotated, Final, Literal, NamedTuple +from typing import TYPE_CHECKING, Annotated, Final, Literal, NamedTuple from pydantic import ( ConfigDict, @@ -27,7 +27,10 @@ from pydantic import ( from litellm.types.llms.base import LiteLLMBaseModel -if sys.version_info >= (3, 11): +if TYPE_CHECKING: + import sre_constants + import sre_parse +elif sys.version_info >= (3, 11): from re import _constants as sre_constants from re import _parser as sre_parse else: