Skip to content

Source location range issue for dictionary  #55577

@tugsbayasgalan

Description

@tugsbayasgalan

🐛 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

Metadata

Metadata

Assignees

Labels

OSS contribution wantedPR from open source contributors welcome to solve this issue.good first issuemodule: bootcampWe plan to do a full writeup on the issue, and then get someone to do it for onboardingoncall: jitAdd this issue/PR to JIT oncall triage queue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions