简体   繁体   中英

Variable auto completion not working in Eclipse with Pydev

  • Windows: Windows 7 Professional
  • Python: python-3.6.1-amd64.exe
  • pyodbc: pyodbc-4.0.16-cp36-cp36m-win_amd64.whl
  • Eclipse: Neon.3Release(4.6.3) Build id: 20170314-1500
  • PyDev for Eclipse: 5.7.0201704111357

After I installed pyodbc by run pip install pyodbc-4.0.16-cp36-cp36m-win_amd64.whl , I got unresolved import pyodbc in Eclipse. So I manually added "pyodbc" under Python Interpreter > Forced Builtins and "unresolved import pyodbc" issue solved in Eclipse.

However, auto completion does not work for variable in Eclipse with Pydev. I can get auto completion for pyodbc.connect but not conn.cursor() unless I define conn = pyodbc.Connection .

Auto completion not working for variable conn

import pyodbc

if __name__ == '__main__':
    conn = pyodbc.connect('Connecting String....')
    cur = conn.Cursor()

Auto completion works for variable conn

import pyodbc

if __name__ == '__main__':
    conn = pyodbc.Connection
    conn = pyodbc.connect('Connecting String....')
    cur = conn.Cursor()

This is mostly because PyDev can't infer what pyodbc.connect returns (it can't really execute that, it can only see that it's a method call and try to guess from its docstring).

You can help it though by adding type hints in docstrings as:

#: :type conn: pyodbc.Connection

See: http://www.pydev.org/manual_adv_type_hints.html for more info

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