Resnet implementation: forward() takes 1 positional argument but 2 were given
I wrote this code and when I run it I get the following error: forward() takes 1 positional argument but 2 were given. As far as I know, I am passing only one argument to forward().

ResNet is a basic residual block

class ResNet(nn.Module):
    def __init__(self, in_channels, mid_channels, mid2_channels ,out_channels):
        super().__init__()
        self.conv1 = nn.Conv2d(in_channels,mid_channels,kernel_size = 3, stride = 1, padding = 1)
        self.conv1_bn = nn.BatchNorm2d(mid_channels)
        self.conv2 = nn.Conv2d(mid_channels,mid2_channels,kernel_size = 3, stride = 1, padding = 1)
        self.conv2_bn = nn.BatchNorm2d(mid2_channels)
        self.conv3 = nn.Conv2d(mid2_channels,out_channels,kernel_size = 3, stride = 1, padding = 1)
        self.conv3_bn = nn.BatchNorm2d(out_channels)
        if (in_channels != out_channels):
            self.conv_shortcut = nn.Conv2d(in_channels, out_channels, kernel_size = 1, stride = 1, padding = 0 )

    def forward(self, X):
         X_shortcut = X
        X = F.relu(self.conv1(X))
        X =  self.conv1_bn(X)
        X = F.relu(self.conv2(X))
        X =  self.conv2_bn(X)
        X = F.relu(self.conv2(X))
        X =  self.conv2_bn(X)
        if (in_channels == out_channels):
            X = self.conv3(X) + X_shortcut
        else:
            X = self.conv3(X) + self.conv_shortcut(X_shortcut)
        X = self.conv3_bn(F.relu(x))
        return X


This the method for generating a model using the given layers.

class TotalNet(nn.Module):
    def __init__(self, Layers):
        super().__init__()
        self.hidden = nn.ModuleList()
        self.hidden.append(nn.BatchNorm2d(1))
        for i in range(0,len(Layers)-1,3):
            in_channels, mid_channels, mid2_channels, out_channels = Layers[i:(i+4)]
            self.hidden.append(ResNet(in_channels, mid_channels, mid2_channels, out_channels))
            self.hidden.append(nn.Flatten())
            
    def forward(self, X):
        X = self.hidden(X)
        return X


the following is how I am calling the function:

test = TotalNet([9,2,9,9,9,9,9,9,9,9])
a = torch.rand((1,9,9), dtype = torch.float32)
test(a)


I realized that I was passing the X to the nn.ModuleList. This is incorrect that the right way would be to apply X to the elements of nn.ModuleList and updating the values of X.
In other words, the forward function of TotalNet should be the following:
for operation in self.hidden:
            X = operation(X)
        return X

