python-oracledb icon indicating copy to clipboard operation
python-oracledb copied to clipboard

Proper type hint of Cursor.execute parameters

Open rob975 opened this issue 1 year ago • 2 comments

Below function works fine but I get an error from Mypy saying parameters type, Optional[dict], is not compatible with Union[dict, list, tuple].

def dummy(cursor: Cursor, parameters: dict | None) -> None:
    for row in cursor.execute("select current_date from dual", parameters):
        print(row[0])

Given parameters defaults to None, I believe type hint should include None too.

rob975 avatar Aug 30 '24 09:08 rob975

I've pushed a patch that corrects this issue among others in the oracleb.Cursor and oracledb.AsyncCursor classes. If you are able to build from source you can verify that it works for you, too.

I've added a new subdirectory in the tests folder called stc where I can add additional type checking tests like this one. That will happen over time.

anthony-tuininga avatar Aug 30 '24 18:08 anthony-tuininga

I built from source and verified It works. Thank you.

rob975 avatar Sep 02 '24 12:09 rob975

This was included in python-oracledb 2.5.0 which was just released.

anthony-tuininga avatar Nov 05 '24 20:11 anthony-tuininga