Skip to content

Change return types to avoid IDE errors/warnings  #60

@HPRIOR

Description

@HPRIOR

Various IDEs complain about the Cursor type not being iterable even though it is.

For example:

def example(): with connect( user="***", password="***", dsn="***") as connection: with connection.cursor() as cursor: execute_stmt = cursor.execute("select * from table") if execute_stmt: return [r for r in execute_stmt]

When using the pyright lsp with neovim, I get this error:

 "Type[Cursor]" is not iterable 

When using pycharm I get a warning of:

Expected type 'collections.Iterable', got 'Type[Cursor]' instead 

As temporary work around I have modified the signature of the execute method of Cursor class in oracledb/cursor.py to return Union['Cursor', None] instead of Union[Type["Cursor"], None].

original:

 def execute(self, statement: Union[str, None], parameters: Union[list, tuple, dict]=None, **keyword_parameters: dict) -> Union[Type["Cursor"], None]:

new:

 def execute(self, statement: Union[str, None], parameters: Union[list, tuple, dict]=None, **keyword_parameters: dict) -> Union['Cursor', None]:

OS: macOS BigSur v11.6.1
pycharm 2022.1.4 (Professional Edition)
NVIM v0.7.2
pyright 1.1.270

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions