pytorch
a7a09adb - Add location information for assertions in `torch.jit.annotations.try_ann_to_type` (#96423)

Commit
1 year ago
Add location information for assertions in `torch.jit.annotations.try_ann_to_type` (#96423) There are two assertions in `torch.jit.annotations.try_ann_to_type` that could benefit from adding source level location information. For example, the current assertion: ``` msg = "Unsupported annotation {} could not be resolved because {} could not be resolved." assert valid_type, msg.format(repr(ann), repr(contained)) ``` reports: ``` AssertionError: Unsupported annotation typing.Union[typing.Dict, NoneType] could not be resolved because typing.Dict could not be resolved at ``` I find it beneficial to know from which line of code this assertion was triggered. Adding the location information then reports: ``` AssertionError: Unsupported annotation typing.Union[typing.Dict, NoneType] could not be resolved because typing.Dict could not be resolved at File "/home/schuetze/Documents/work/github/prediction_net/multimodal/models/heads/retina_head.py", line 189 def forward(self, fpn_features: t.Dict[str, torch.Tensor], inputs: t.Dict[str, torch.Tensor], gts: t.Optional[t.Dict] = None) -> t.Dict[str, t.Any]: ~~~~~~~~~~~~~~~~~~ <--- HERE """ """ ``` Adding these location information are related to #96420 but these changes in this PR can be made without any API changes. Pull Request resolved: https://github.com/pytorch/pytorch/pull/96423 Approved by: https://github.com/davidberard98
Committer
Parents
Loading