Closed
Description
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.
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
'''
Metadata
Metadata
Assignees
Labels
No labels