首页 > 试题广场 >

以下使用TypeVar bound的代码,类型检查器对fun

[单选题]
以下使用TypeVar bound的代码,类型检查器对func(42)会报什么?
```python
from typing import TypeVar
  • = TypeVar('T', bound=str)
    def func(x: T) -> T:
    return x
    result = func(42)
    ```
  • 无错误,T可以绑定为int
  • 类型错误,int不是str的子类型
  • 运行时抛出TypeError
  • 类型错误,TypeVar不能使用bound参数
这A选项是啥玩意?
发表于 2026-03-19 15:57:01 回复(0)