googleapis / googleapis/python-aiplatform

`TypeError: Plain typing.TypeAlias is not valid as type argument` in vertexai/_genai/_agent_engines_utils.py on Python 3.10

未关闭
#6,404 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
api: vertex-ai
主要语言
Python
星标
905
派生
465
平均合并
1 天 13 小时
30 天内合并 PR
44

描述

#### Environment details
- Python: 3.10.1
- google-cloud-aiplatform: 1.140.0
- google-adk: 1.26.0
- OS: Linux (Kubernetes)
- **Buggy versions**: 1.136.0, 1.137.0, 1.138.0, 1.139.0, 1.140.0
- **Python versions affected**: 3.10.x
- **Last working version**: 1.135.0

#### Steps to reproduce

Not sure this was encountered while using google adk which has this as a dependency.
Full traceback of error after making a POST request to create a session which triggered this error:

```
Traceback (most recent call last):
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/google/adk/cli/adk_web_server.py", line 660, in _create_session
session = await self.session_service.create_session(
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/google/adk/sessions/vertex_ai_session_service.py", line 115, in create_session
api_response = await api_client.agent_engines.sessions.create(
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/vertexai/_genai/client.py", line 111, in agent_engines
self._agent_engines = importlib.import_module(
File "/root/.pyenv/versions/3.10.1/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/vertexai/_genai/agent_engines.py", line 34, in
from . import _agent_engines_utils
File "/root/.pyenv/versions/3.10/lib/python3.10/site-packages/vertexai/_genai/_agent_engines_utils.py", line 289, in
ADKAgent: Optional[TypeAlias] = BaseAgent
File "/root/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 311, in inner
return func(*args, **kwds)
File "/root/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 402, in __getitem__
return self._getitem(self, parameters)
File "/root/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 528, in Optional
arg = _type_check(parameters, f"{self} requires a single type.")
File "/root/.pyenv/versions/3.10.1/lib/python3.10/typing.py", line 171, in _type_check
raise TypeError(f"Plain {arg} is not valid as type argument")
TypeError: Plain typing.TypeAlias is not valid as type argument
```

### Root Cause

**File**: `vertexai/_genai/_agent_engines_utils.py`
**Line**: 289

```python
if typing.TYPE_CHECKING:
from google.adk.agents import BaseAgent

ADKAgent: TypeAlias = BaseAgent
else:
try:
from google.adk.agents import BaseAgent

ADKAgent: Optional[TypeAlias] = BaseAgent # this is the line causing issues
except (ImportError, AttributeError):
ADKAgent = None # type: ignore[no-redef]
```

Not sure the syntax `Optional[TypeAlias]` valid 3.10? Confusing though since I think the syntax is valid unclear why it would cause this runtime error.

**Introduced in**: https://github.com/googleapis/python-aiplatform/commit/d8cc50dd67

### Workaround
Pin to version 1.135.0 or earlier:
```toml
google-cloud-aiplatform = "1.135.0"
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。