Skip to content

Mismatch between documentation and returned type #70

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

Closed
Saharsh-R opened this issue Aug 1, 2024 · 2 comments · Fixed by #71
Closed

Mismatch between documentation and returned type #70

Saharsh-R opened this issue Aug 1, 2024 · 2 comments · Fixed by #71

Comments

@Saharsh-R
Copy link

Saharsh-R commented Aug 1, 2024

Describe the bug
In the documentation, https://bloomberg.github.io/python-comdb2/dbapi2.html#comdb2.dbapi2.Cursor.fetchall, it says it returns a list, but in vscode, when I do reveal_type, i get a Sequence.

a =cursor.execute(query, params).fetchall()
reveal_type(a) # Type of "a" is "Sequence[Any]"Pylance

Expected behavior
Either documentation should say it returns a Sequence, or a list should be returned.

Screenshots
Shot 2024-08-01 at 13 44 37

Environment (please complete the following information):

  • Operating System and Version: Python3.12, Macos v14.5

Usecase

I wanted to do two queries and append the result. But since it was a Sequence, pylance was complaining.

def get_unique_key_of_row(row: Any) -> str:
    return f'{row['unique_key_1']}_{row['unique_key_2']}'


def get_rows_util(param: str) -> Sequence[Any]:
    query = "select * from table where param = %(param)s"
    connection = get_connection()
    with closing(connection):
        cursor = connection.cursor()
        return cursor.execute(query, {"param": param}).fetchall()


def process_some_logic() -> List[Any]:
    records_1 = get_rows_util("dog")
    records1_key_set: Set[str] = {get_unique_key_of_row(x) for x in records_1}
    records_2_filtered = [x for x in get_rows_util("cat") if get_unique_key_of_row(x) not in records1_key_set]
    return records_1 + records_2_filtered
    '''
    Operator "+" not supported for types "Sequence[Any]" and "list[Any]"PylancereportOperatorIssue
    Return type is unknownPylancereportUnknownVariableType
    '''

Shot 2024-08-01 at 13 54 53

@godlygeek
Copy link
Contributor

godlygeek commented Aug 2, 2024

Changing the annotation to say that we return a list seems fair enough. Want to send a PR?

@Saharsh-R
Copy link
Author

Changing the annotation to say that we return a list seems fair enough. Want to send a PR?

Yes. Will Get right to it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants