Reputation: 8515
Python beginner here. Don't understand why intellisense for some psycopg2 objects doesn't work in 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:
cannot step into the definition here:
Do I have to somehow specify the types of the objects during declaration e.g.:
cursor: cursor = None
Upvotes: 1
Views: 318
Reputation: 8515
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:
from psycopg2.extensions import cursor, connection
import psycopg2
from config import db_config
from datetime import datetime
conn: connection = None
cursor: cursor = None
Upvotes: 1