在学习 Flask web 教程里, super(User, self).__init__(**kwargs) 为什么一直被 IDE 提示错误: unexpected argument?

2017 年 9 月 26 日
 miniyao

用 Pycharm 看的这个代码,super(User, self).__init__(**kwargs) 中的 ···**kwargs``` 部分一直被 Pycharm 提示:unexpected argument

#models.py

class User(UserMixin, db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(64), unique=True, index=True)

    ... ...

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)  # 这里 IDE 提示 **kwargs:unexpected argument
        ... ...
        self.followed.append(Follow(followed=self))
3885 次点击
所在节点    Python
7 条回复
cxbats
2017 年 9 月 27 日
因为你忘了传 self
zwgmlr3
2017 年 9 月 27 日
不妨看一下语法 ** 是什么意思?
miniyao
2017 年 9 月 27 日
@cxbats
@zwgmlr3

感觉这个像是 Pycharm 的 bug,对 super()继承父类的参数识别不准确吧。有了解的同学,请指正。
wangkai123
2017 年 9 月 27 日
**kwargs->kwargs
wangkai123
2017 年 9 月 27 日
好像没有用 hhh
zwgmlr3
2017 年 9 月 27 日
看一下你的 UserMixin 和 db.Model 的 __init__ 方法怎么定义的,下面这种写法肯定会报错啊
class UserMixin():
def __init__(self):
pass


class User(UserMixin):
__tablename__ = 'users'

def __init__(self, **kwargs):
super(User, self).__init__(**kwargs)
zhusimaji
2017 年 9 月 28 日
老铁没毛病啊,这个应该是你 pycharm 的问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/393894

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX