Type annotation for `worksheet[start:end]` is incorrect
worksheet[start:end]
seems to return a tuple[tuple[Cell]]
, but the type annotations imply that it returns a tuple[cell]
.
You can see this issue in the following code:
from typing import reveal_type
from openpyxl import Workbook
from openpyxl.worksheet.worksheet import Worksheet
wb = Workbook()
ws = wb.active
if isinstance(ws, Worksheet):
for cell in ws["A1":"A12"]:
reveal_type(cell)
Type checkers believe one thing:
$ pyright tuple_excel.py
tuple_excel.py:9:21 - information: Type of "cell" is "Cell"
Python disagrees:
$ python tuple_excel.py
Runtime type is 'tuple'
Versions:
openpyxl==3.1.2
types-openpyxl==3.1.0.20240402
Python 3.12.2
Edited by Michael Milton