Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change return types to avoid IDE errors/warnings #60

Closed
HPRIOR opened this issue Sep 9, 2022 · 1 comment
Closed

Change return types to avoid IDE errors/warnings #60

HPRIOR opened this issue Sep 9, 2022 · 1 comment
Labels
enhancement New feature or request patch available

Comments

@HPRIOR
Copy link

HPRIOR commented Sep 9, 2022

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

@anthony-tuininga
Copy link
Member

Included in python-oracledb 1.1.1 which was just released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request patch available
Projects
None yet
Development

No branches or pull requests

2 participants