简体   繁体   中英

Why can't PyCharm show PyTorch Module object attributes in debug mode

I define a sub-class of PyTorch's Module in PyCharm and create an instance a :

from torch.nn import Module

class AModule(Module):
    def __init__(self):
        self.something = 10

    def __repr__(self):
        return "AModule"

a = AModule()

If I run the debugger and examine a , I can't see its attributes:

在此处输入图像描述

I checked and Module is written in Python (as opposed to being implemented in C), so why is that?

This is caused by not having properly initialized Module with a super call in the first like of __init__ :

super(AModule, self).__init__()

However, PyCharm could have shown more useful information, so I created this issue .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM