Pylint can't find SQLAlchemy query member

前端 未结 13 1584
予麋鹿
予麋鹿 2021-01-30 08:25

I have a Flask (v0.10.1) application using Flask-SQLAlchemy (v2.0) and I\'m trying to configure Pylint to check it. Running with Python 3.4.2.

First error was:



        
13条回答
  •  耶瑟儿~
    2021-01-30 09:01

    This is how I'm dealing with the issue for scoped_session. Trivial to extend to check for more cls names with SQLAlchemy attributes.

    from astroid import MANAGER
    from astroid import scoped_nodes
    
    def register(_linter):
        pass
    
    def transform(cls):
        if cls.name == 'scoped_session':
            for prop in ['add', 'delete', 'query', 'commit', 'rollback']:
                cls.locals[prop] = [scoped_nodes.Function(prop, None)]
    
    MANAGER.register_transform(scoped_nodes.Class, transform)
    

    Adapted from https://docs.pylint.org/en/1.6.0/plugins.html . Then make sure pylint loads your plugin.

    pylint -E --load-plugins warning_plugin Lib/warnings.py

    (or load it in pylintrc)

提交回复
热议问题