pytorch
cb3b8a33 - [JIT] Disallow plain Dict type annotation without arg (#44334)

Commit
5 years ago
[JIT] Disallow plain Dict type annotation without arg (#44334) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/44334 **Summary** This commit detects and prohibits the case in which `typing.Dict` is used as an annotation without type arguments (i.e. `typing.Dict[K, V]`). At present, `typing.Dict` is always assumed to have two arguments, and when it is used without them, `typing.Dict.__args__` is nonempty and contains some `typing.TypeVar` instances, which have no JIT type equivalent. Consequently, trying to convert `typing.Dict` to a JIT type results in a `c10::DictType` with `nullptr` for its key and value types, which can cause a segmentation fault. This is fixed by returning a `DictType` from `jit.annotations.try_ann_to_type` only if the key and value types are converted successfully to a JIT type and returning `None` otherwise. **Test Plan** This commit adds a unit test to `TestDict` that tests the plain `Dict` annotations throw an error. **Fixes** This commit closes #43530. Test Plan: Imported from OSS Reviewed By: gmagogsfm Differential Revision: D23610766 Pulled By: SplitInfinity fbshipit-source-id: 036b10eff6e3206e0da3131cfb4997d8189c4fec
Author
Meghan Lele
Parents
Loading