推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
miniyao
V2EX  ›  Python

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

  •  
  •   miniyao · Sep 26, 2017 · 3864 views
    This topic created in 3151 days ago, the information mentioned may be changed or developed.

    用 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))
    
    7 replies    2017-09-28 08:49:57 +08:00
    cxbats
        1
    cxbats  
       Sep 27, 2017 via Android
    因为你忘了传 self
    zwgmlr3
        2
    zwgmlr3  
       Sep 27, 2017 via Android
    不妨看一下语法 ** 是什么意思?
    miniyao
        3
    miniyao  
    OP
       Sep 27, 2017
    @cxbats
    @zwgmlr3

    感觉这个像是 Pycharm 的 bug,对 super()继承父类的参数识别不准确吧。有了解的同学,请指正。
    wangkai123
        4
    wangkai123  
       Sep 27, 2017
    **kwargs->kwargs
    wangkai123
        5
    wangkai123  
       Sep 27, 2017
    好像没有用 hhh
    zwgmlr3
        6
    zwgmlr3  
       Sep 27, 2017
    看一下你的 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
        7
    zhusimaji  
       Sep 28, 2017
    老铁没毛病啊,这个应该是你 pycharm 的问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1059 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 18:43 · PVG 02:43 · LAX 11:43 · JFK 14:43
    ♥ Do have faith in what you're doing.