-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Openpyxl iter_rows is no more compatible with next function #13151
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
Comments
@mutricyl Do you think you could provide a more complete example? I am unable to replicate. from openpyxl.workbook import Workbook
from typing_extensions import reveal_type
def foo(unknown_values_only: bool) -> None:
reveal_type(Workbook()["sheet"].iter_rows())
reveal_type(next(Workbook()["sheet"].iter_rows()))
reveal_type(Workbook()["sheet"].iter_rows(values_only=True))
reveal_type(next(Workbook()["sheet"].iter_rows(values_only=True)))
reveal_type(Workbook()["sheet"].iter_rows(values_only=unknown_values_only))
reveal_type(next(Workbook()["sheet"].iter_rows(values_only=unknown_values_only)))
The error seem to imply that the generic type of the expected My guess would be that you are assigning to a predefined value that doesn't match the inferred return type of |
I got the point ! I spent some time replicating the issue and there is a replicable example: import datetime
from typing import TypeAlias, Union
import openpyxl
from openpyxl.workbook import Workbook
from typing_extensions import reveal_type
wb = Workbook()
openpyxl_value_types: TypeAlias = Union[str, float, datetime.datetime, None,
int]
openpyxl_types: TypeAlias = Union[openpyxl_value_types,
openpyxl.cell.cell.Cell]
def test(value: bool, sheet: str) -> tuple[openpyxl_types, ...]:
wb = Workbook()
reveal_type(next(wb[sheet].iter_rows(values_only=value)))
return next(wb[sheet].iter_rows(values_only=value)) So I bascially miss the Thanks for the help @Avasam , I'll close the issue. |
The following was fine with mypy until
types-openpyxl-3.1.5.20241114
:But when I upgraded to
types-openpyxl-3.1.5.20241126
I have the following error:error: Argument 1 to "next" has incompatible type "Generator[tuple[Cell | MergedCell, ...], None, None] | Generator[tuple[str | float | datetime | None, ...], None, None]"; expected "SupportsNext[tuple[str | float | datetime | int | None | Cell, ...]]" [arg-type]
I do not understand why a Generator is not considered as SupportsNext ?
The text was updated successfully, but these errors were encountered: