Skip to content

Mismatch between documentation and returned type #70

Closed
@Saharsh-R

Description

@Saharsh-R

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions