pytorch/pytorch

Source location range issue for dictionary

已關閉

#55,577 建立於 2021年4月8日

 (29 則留言) (0 個反應) (1 位負責人)Python (28,910 個分叉)batch import
OSS contribution wantedgood first issuemodule: bootcamponcall: jit

倉庫指標

星標
 (102,472 顆星)
PR 合併指標
 (平均合併 1天 10小時) (30 天內合併 42 個 PR)

描述

🐛 Bug

During our hackathon today, I ran into this weird error highlighting.

import torch
from typing import Dict

@torch.jit.script
def missing_index(x: Dict[str, int]) -> int:
    return x['dne']

missing_index({'item': 20, 'other_item': 120})

This code outputs:

     9 
     10 
---> 11 missing_index({'item': 20, 'other_item': 120})

RuntimeError: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript (most recent call last):
  File "<ipython-input-6-f7e8ae85d5ad>", line 8, in missing_index
@torch.jit.script
def missing_index(x: Dict[str, int]) -> int:
    return x['dne']
           ~~~~ <--- HERE
RuntimeError: KeyError: dne

I feel like the highlighted range should be either shorter or long enough to highlight the entire statement.

cc @gmagogsfm

貢獻者指南