'str' object has no attribute '__module__' in jit is_final
Labels: oncall: jit

### 🐛 Describe the bug

A minimal code to reproduce this error is:

```python
from __future__ import annotations

import torch
from torch import nn

class Name:
    pass

class Model(nn.Module):
    name: Name

    def __init__(self) -> None:
        super().__init__()
        self.module = nn.Conv2d(3, 3, kernel_size=1)

    def forward(self, x):
        return self.module(x)

model = Model()
torch.jit.script(model)
```

It crashes with:

```
Traceback (most recent call last):
  File "test.py", line 20, in <module>
    torch.jit.script(model)
  File "/home/azureuser/miniconda3/envs/nni/lib/python3.8/site-packages/torch/jit/_script.py", line 1286, in script
    return torch.jit._recursive.create_script_module(
  File "/home/azureuser/miniconda3/envs/nni/lib/python3.8/site-packages/torch/jit/_recursive.py", line 455, in create_script_module
    concrete_type = get_module_concrete_type(nn_module, share_types)
  File "/home/azureuser/miniconda3/envs/nni/lib/python3.8/site-packages/torch/jit/_recursive.py", line 406, in get_module_concrete_type
    concrete_type = concrete_type_store.get_or_create_concrete_type(nn_module)
  File "/home/azureuser/miniconda3/envs/nni/lib/python3.8/site-packages/torch/jit/_recursive.py", line 347, in get_or_create_concrete_type
    concrete_type_builder = infer_concrete_type_builder(nn_module)
  File "/home/azureuser/miniconda3/envs/nni/lib/python3.8/site-packages/torch/jit/_recursive.py", line 222, in infer_concrete_type_builder
    if torch._jit_internal.is_final(ann):
  File "/home/azureuser/miniconda3/envs/nni/lib/python3.8/site-packages/torch/_jit_internal.py", line 943, in is_final
    return ann.__module__ in {'typing', 'typing_extensions'} and \
AttributeError: 'str' object has no attribute '__module__'
```

The same script works fine when `from __future__ import annotations` is removed, or `name: Name` is removed.

### Versions

Collecting environment information...
PyTorch version: 1.12.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.10.2
Libc version: glibc-2.27

Python version: 3.8.12 (default, Oct 12 2021, 13:49:34)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-1090-azure-x86_64-with-glibc2.17
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy==0.961
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.23.3
[pip3] pytorch-lightning==1.6.1
[pip3] torch==1.12.1
[pip3] torchaudio==0.12.1
[pip3] torchmetrics==0.6.0
[pip3] torchvision==0.13.1
[conda] blas                      1.0                         mkl  
[conda] cpuonly                   2.0                           0    pytorch
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0            py38h7f8727e_0  
[conda] mkl_fft                   1.3.1            py38hd3c417c_0  
[conda] mkl_random                1.2.2            py38h51133e4_0  
[conda] numpy                     1.23.3           py38h14f4228_0  
[conda] numpy-base                1.23.3           py38h31eccc5_0  
[conda] pytorch                   1.12.1              py3.8_cpu_0    pytorch
[conda] pytorch-lightning         1.6.1                    pypi_0    pypi
[conda] pytorch-mutex             1.0                         cpu    pytorch
[conda] torchaudio                0.12.1                 py38_cpu    pytorch
[conda] torchmetrics              0.6.0                    pypi_0    pypi
[conda] torchvision               0.13.1                 py38_cpu    pytorch