Repository: pytorch
Issue: `@torch.jit.unused` does not properly ignore unsupported function signature
Labels: oncall: jit

### 🐛 Describe the bug

Per my understanding, `@torch.jit.unused` should make jit compiler completely ignore a method in the class as if that method never existed. However, it's not the case. The compiler is still trying to parse the method signature even if `@torch.jit.unused` is used.

A simple example:
```python
from typing_extensions import Self
import torch

@torch.jit.script
@dataclass
class Data:
    a: int

    @classmethod
    @torch.jit.unused
    def factory_method(cls, a: int = 1) -> Self:
        return cls(a)
```
This piece of code will raise the following error:
```
RuntimeError: 
Unknown type name 'Self':
  File "xxx.py", line 18
    @classmethod
    @torch.jit.unused
    def factory_method(cls, a: int = 1) -> Self:
                                           ~~~~ <--- HERE
        return cls(a)
```

I searched in the repo and found that there was a related PR(#39336), but it doesn't seem to work as expected.


### Versions

```
Collecting environment information...
PyTorch version: 1.13.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 13.2 (x86_64)
GCC version: Could not collect
Clang version: 14.0.6
CMake version: version 3.25.2
Libc version: N/A

Python version: 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:27:35) [Clang 14.0.6 ] (64-bit runtime)
Python platform: macOS-13.2-x86_64-i386-64bit
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

CPU:
Apple M1 Max

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] pytorch-lightning==1.9.0
[pip3] torch==1.13.1
[pip3] torch-cluster==1.6.0
[pip3] torch-geometric==2.2.0
[pip3] torch-scatter==2.1.0
[pip3] torch-sparse==0.6.16
[pip3] torch-spline-conv==1.2.1
[pip3] torchaudio==0.13.1
[pip3] torchmetrics==0.11.2
[conda] blas                      2.112                       mkl    conda-forge
[conda] blas-devel                3.9.0              12_osx64_mkl    conda-forge
[conda] libblas                   3.9.0              12_osx64_mkl    conda-forge
[conda] libcblas                  3.9.0              12_osx64_mkl    conda-forge
[conda] liblapack                 3.9.0              12_osx64_mkl    conda-forge
[conda] liblapacke                3.9.0              12_osx64_mkl    conda-forge
[conda] mkl                       2021.4.0           h89fa619_689    conda-forge
[conda] mkl-devel                 2021.4.0           h694c41f_690    conda-forge
[conda] mkl-include               2021.4.0           hf224eb6_689    conda-forge
[conda] numpy                     1.23.5          py310h1b7c290_0    conda-forge
[conda] pyg                       2.2.0           py310_torch_1.13.0_cpu    pyg
[conda] pytorch                   1.13.1                 py3.10_0    pytorch
[conda] pytorch-cluster           1.6.0           py310_torch_1.13.0_cpu    pyg
[conda] pytorch-lightning         1.9.0                    pypi_0    pypi
[conda] pytorch-scatter           2.1.0           py310_torch_1.13.0_cpu    pyg
[conda] pytorch-sparse            0.6.16          py310_torch_1.13.0_cpu    pyg
[conda] pytorch-spline-conv       1.2.1           py310_torch_1.13.0_cpu    pyg
[conda] torchaudio                0.13.1                py310_cpu    pytorch
[conda] torchmetrics              0.11.2          py310h20db666_0  
```

cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel