我了解内置类型。但是我如何指定稀有对象,例如数据库连接对象?
def get_connection_and_cursor() -> tuple[psycopg2.extensions.cursor, psycopg2.extensions.connection]:
connection = psycopg2.connect(dbname=db_name, user=db_user, password=db_password, host='127.0.0.1', port="5432")
# connection.autocommit = True
cursor = connection.cursor()
return connection, cursor
Run Code Online (Sandbox Code Playgroud)
检查类型,以下是输出:
type(cursor):psycopg2.extensions.cursor和type(connection)psycopg2.extensions.connection: 。我应该用它做什么?