RuntimeError: __class__ not set defining ‘‘ as <class>. Was __classcell__ propagated to type.__new_

问题描述

报错提示类中不能有super的方法。 

问题:

RuntimeError: __class__ not set defining 'AttentionModelFixed' as <class 'attention_model.AttentionModelFixed'>. Was __classcell__ propagated to type.__new__?

报错代码: 

class AttentionModelFixed(NamedTuple):

    def __getitem__(self, key):
        if xxxx:
            return AttentionModelFixed(xxx)            )
        return super(AttentionModelFixed, self).__getitem__(key)

 


解决方案:

启动正确的虚拟环境。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
引用\[1\]中提到了一个与Python相关的错误信息,即"RuntimeError: super-class __init__() of %S was never called"。这个错误通常发生在类的初始化方法中没有调用父类的初始化方法时。引用\[2\]和引用\[3\]中也提到了类似的错误信息,即"TypeError: unbound method a() must be called with A instance as first argument (got nothing instead)"。这个错误通常发生在调用一个未绑定的方法时没有传递实例作为第一个参数。根据这些引用内容,可以推断出你遇到的问题是在一个类的初始化方法中没有调用父类的初始化方法,导致出现了"RuntimeError: super-class __init__() of type was never called"的错误。为了解决这个问题,你需要在子类的初始化方法中调用父类的初始化方法,可以使用super()函数来实现。这样可以确保父类的初始化方法被正确地调用,避免出现这个错误。 #### 引用[.reference_title] - *1* [Python:使用decorator更改类类型并保留它的方法](https://blog.csdn.net/weixin_27298377/article/details/118901361)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [python 新手遇到的问题](https://blog.csdn.net/weixin_39786850/article/details/111423888)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值