Repository: pytorch
Issue: [JIT] If a python function type comment is referring to a wrong type, JIT frontend gives a not helpful error message
Labels: oncall: jit,triaged

```
        dst_worker_name = worker_name((self.rank + 1) % self.world_size)
        input_0 = torch.ones(2, 2)
        input_1 = 1
        expected_res = torch.add(input_0, input_1)

        @torch.jit.ignore
        def python_return_future():
            # type: () -> Future[Tensor]
            fut = rpc.rpc_async(dst_worker_name, torch.add, (input_0, input_1), {})
            return fut

        @torch.jit.script
        def script_use_future():
            # type: () -> Tensor
            fut = python_return_future()
            return fut.wait()

        res = script_use_future()
        self.assertEqual(res, expected_res)
```


The error message is
```
/data/users/shihaoxu/fbsource/fbcode/buck-out/dev/gen/caffe2/test/distributed/rpc/jit/rpc_fork#binary,link-tree/torch/testing/_internal/common_distributed.py:181: Caught exception:
Traceback (most recent call last):
  File "/data/users/shihaoxu/fbsource/fbcode/buck-out/dev/gen/caffe2/test/distributed/rpc/jit/rpc_fork#binary,link-tree/torch/testing/_internal/common_distributed.py", line 178, in wrapper
    fn(self)
  File "/data/users/shihaoxu/fbsource/fbcode/buck-out/dev/gen/caffe2/test/distributed/rpc/jit/rpc_fork#binary,link-tree/torch/testing/_internal/dist_utils.py", line 69, in new_test_method
    return_value = old_test_method(self, *arg, **kwargs)
  File "/data/users/shihaoxu/fbsource/fbcode/buck-out/dev/gen/caffe2/test/distributed/rpc/jit/rpc_fork#binary,link-tree/torch/testing/_internal/distributed/rpc/jit/rpc_test.py", line 35, in test_script_call_python_return_future
    @torch.jit.script
  File "/data/users/shihaoxu/fbsource/fbcode/buck-out/dev/gen/caffe2/test/distributed/rpc/jit/rpc_fork#binary,link-tree/torch/jit/__init__.py", line 1296, in script
    fn = torch._C._jit_script_compile(qualified_name, ast, _rcb, get_default_args(obj))
  File "/data/users/shihaoxu/fbsource/fbcode/buck-out/dev/gen/caffe2/test/distributed/rpc/jit/rpc_fork#binary,link-tree/torch/jit/annotations.py", line 80, in get_signature
    signature = parse_type_line(type_line, rcb, loc)
  File "/data/users/shihaoxu/fbsource/fbcode/buck-out/dev/gen/caffe2/test/distributed/rpc/jit/rpc_fork#binary,link-tree/torch/jit/annotations.py", line 163, in parse_type_line
    ret_ann = eval(ret_ann_str, {}, EvalEnv(rcb))  # noqa: P204
  File "<string>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable
exiting process with exit code: 10
```
Expected error

```
RuntimeError: Failed to parse the return type of a type annotation: name 'Future' is not defined
```
This can be fixed by change 
```
    class closure_lookup(object):
        # This is a class since `closure` is a dict and it's easier in
        # `env_helper` if everything just works with `getattr` calls
        def __getattr__(self, key):
            if key in closure:
                return closure[key]
            elif hasattr(builtins, key):
                return getattr(builtins, key)
            raise KeyError(key)  # This line is changed.
```
in "torch/_jit_internal.py".

But this fails other tests, I am suspecting other callsites didn't consider handling error, maybe they use None comparison?

cc @suo