Repository: pytorch
Issue: JIT is overriding variables of type List[int] to type Tuple[int, int] for an unknown reason during function calls
Labels: oncall: jit

### 🐛 Describe the bug

JIT / Torchscript appears to be mistakenly changing a variable of type `List[int]` to a tuple with a type of `Tuple[int, int]`.


## To Reproduce

Run this class and function combo and convert it to JIT:

```
from typing import List, Union

import torch

class TestModule(torch.nn.Module):

    __constants__ = ["size"]

    def __init__(
        self,
        size: Union[int, List[int]],
    ) -> None:
        super().__init__()
        if not hasattr(size, "__iter__"):
            size = [size, size]
        else:
            size = size
        self.size = list(size)
        print(type(self.size))

    def forward(self, input: torch.Tensor) -> torch.Tensor:
        return test_func(input, self.size)


def test_func(
    input: torch.Tensor,
    size: Union[int, List[int]],
) -> torch.Tensor:
    return input

test_module = TestModule(5)
jit_module = torch.jit.script(test_module)
```

Results in the following error message

```
<class 'list'>

---------------------------------------------------------------------------

RuntimeError                              Traceback (most recent call last)

<ipython-input-16-e732aecd3ab2> in <module>()
     48 
     49 test_module = TestModule(5)
---> 50 jit_module = torch.jit.script(test_module)
     51 
     52 out = jit_module(torch.ones(1, 3, 5, 5))

3 frames

/usr/local/lib/python3.7/dist-packages/torch/jit/_recursive.py in create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs)
    366     property_rcbs = [p.resolution_callback for p in property_stubs]
    367 
--> 368     concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults)
    369 
    370 def create_hooks_from_stubs(concrete_type, hook_stubs, pre_hook_stubs):

RuntimeError: 

test_func(Tensor input, Union[int[], int] size) -> (Tensor):
Expected a value of type 'Union[List[int], int]' for argument 'size' but instead found type 'Tuple[int, int]'.
:
  File "<ipython-input-16-e732aecd3ab2>", line 23
    def forward(self, input: torch.Tensor) -> torch.Tensor:
    
        return test_func(input, self.size)
               ~~~~~~~~~ <--- HERE
```


## Expected behavior

There should be no error message, unless I'm missing something major.

## Additional context

This issue is interfering with making my custom transforms JIT compatible.

### Versions

PyTorch version: 1.10.0+cu111
Is debug build: False
CUDA used to build PyTorch: 11.1
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: 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
CMake version: version 3.12.0
Libc version: glibc-2.26

Python version: 3.7.12 (default, Sep 10 2021, 00:21:48)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.104+-x86_64-with-Ubuntu-18.04-bionic
Is CUDA available: False
CUDA runtime version: 11.1.105
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.5
[pip3] torch==1.10.0+cu111
[pip3] torchaudio==0.10.0+cu111
[pip3] torchsummary==1.5.1
[pip3] torchtext==0.11.0
[pip3] torchvision==0.11.1+cu111
[conda] Could not collect