6

Pycharm's type-checking complains about the following block of code (taken from pytorch's docs):

    import torch.nn as nn
    class MyModule(nn.Module):
    def __init__(self):
        super(MyModule, self).__init__()
        self.linears = nn.ModuleList([nn.Linear(10, 10) for i in range(10)])

    def forward(self, x):
        # ModuleList can act as an iterable, or be indexed using ints
        for i, l in enumerate(self.linears):
            x = self.linears[i // 2](x) + l(x)
        #                   ^---------- complains here about:
        # Cannot find reference '[' in 'input:(Any, ...), kwargs:dict) -> Any'
        return x

Is there a way to fix this issue without suppressing it?

Michael Heidelberg
  • 993
  • 11
  • 24
  • 2
    Sounds like an issue with PyCharm itself. Please submit a bug report at https://youtrack.jetbrains.com/issues/PY (and post-back the issue id / link here). – a_guest Oct 06 '19 at 21:31

1 Answers1

0

It is a known issue https://youtrack.jetbrains.com/issue/PY-37601, will be fixed in 2020.1.

user2235698
  • 7,053
  • 1
  • 19
  • 27