PyTorch Fix: Import TypeVar from typing_extensions to Avoid TypeError in CachedMethod
English summary
A PR (#185708) fixes issue #140914 by switching the import of TypeVar from typing to typing_extensions in torch/_inductor/utils.py. Without this change, an import-time TypeError could occur when another vendored copy of typing_extensions monkeypatches typing internals. The fix aligns TypeVar with the existing import of ParamSpec, preserving the CachedMethod[P, RV] convention. The change was approved by Skylion007 and jansel.
Chinese summary
PR #185708修复了issue #140914,在torch/_inductor/utils.py中将TypeVar的导入从typing改为typing_extensions。否则,当另一个被重新打包的typing_extensions副本修改typing内部机制时,可能在导入时引发TypeError。此修复使TypeVar与现有的ParamSpec导入保持一致,保持了CachedMethod[P, RV]的约定。该修复已获Skylion007和jansel批准。
Key points
Importing TypeVar from typing_extensions prevents a TypeError when another typing_extensions copy monkeypatches internals.
从typing_extensions导入TypeVar可防止在另一个typing_extensions副本修改内部时出现TypeError。
The fix preserves the existing CachedMethod[P, RV] pattern used in PyTorch's inductor code.
该修复保留了PyTorch inductor代码中使用的CachedMethod[P, RV]模式。
It is a one-line import change addressing a compatibility edge case.
这是一行导入更改,解决了兼容性边界情况。
The PR was reviewed and approved by two maintainers.
该PR已由两位维护者审查并批准。