Why nn.ModuleList is not a subclass of Sequence

As the code shown below, nn.ModuleList is not subclass of MutableSequence.

In [4]: from collections.abc import MutableSequence, Mapping

In [5]: import torch.nn as nn

In [6]: issubclass(nn.ModuleList, MutableSequence)
Out[6]: False

In [7]: issubclass(nn.ModuleDict, Mapping)
Out[7]: False

The source code of ModuleList is

class ModuleList(Module):

Should we change the code to

class ModuleList(Module, MutableSequence):

Why or why not?

The mutable sequence type comes with quite a few functions that need to be implemented, I’m not sure all of them are there today. Is it worth to implement them? I don’t know.

Best regards

Thomas

Thanks. I also find that ModuleDict implement all the interface except for get in Mapping. I hope that someday they will implement this interface so I can reopen this question.

You could always send a patch it and see if they like it. If you test on ModuleDict, you’ll see what the general sentient is without risking to waste too much effort…

I came across this idea because when I want to reverse a ModuleList instance, my IDE (PyCharm) said that reversed function only accept Sequence or Reversible[_T].