简体   繁体   English

PyCharm 缺少进口 package 的智能感知

[英]PyCharm missing intellisense for imported package

Python beginner here. Python 初学者在这里。 Don't understand why intellisense for some psycopg2 objects doesn't work in PyCharm.不明白为什么某些 psycopg2 对象的智能感知在 PyCharm 中不起作用。

import psycopg2
from config import db_config
from datetime import datetime

conn = None
cursor = None

try:
    params = db_config
    conn = psycopg2.connect(**params)
    cursor = conn.cursor()


except (Exception, psycopg2.DatabaseError) as error:
    print(error)

finally:
    if conn:
        cursor.close()
        conn.close()
        print("connection closed")

cursor() method not offered:未提供 cursor() 方法:

在此处输入图像描述

cannot step into the definition here:无法进入此处的定义:

在此处输入图像描述

Do I have to somehow specify the types of the objects during declaration eg: cursor: cursor = None我是否必须在声明期间以某种方式指定对象的类型,例如: cursor: cursor = None

This is what seems to be fixing the issue, but I'm not sure if this is the right way to go about this issue every time one needs intellisense from imported packages:这似乎是解决问题的方法,但我不确定这是否是 go 关于这个问题的正确方法,每次需要从导入的包中进行智能感知:

from psycopg2.extensions import cursor, connection
import psycopg2
from config import db_config
from datetime import datetime

conn: connection = None
cursor: cursor = None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM