Search code examples
pythonopenpyxlpython-typing

Worksheet.row_dimensions type hinting does not work properly?


Worksheet's row_dimensions raises a Warning when I put an integer in it (for the index of the row to change the height of) although it works (height is changed and script runs correctly).

MRE:

import openpyxl
from openpyxl.worksheet.worksheet import Worksheet

# Load an existing workbook or create a new one
wb = openpyxl.load_workbook('your_workbook.xlsx')
ws: Worksheet = wb.active

# Set the height of row 1 to 25
ws.row_dimensions[1].height = 25  <-- problem

# Save the changes back to the workbook
wb.save('your_workbook.xlsx')

I'm not allowed such warnings, nor am I allowed to add #noqa.

I'm using Python 3.11.1 and the latest version of openpyxl (3.1.2).

enter image description here


Solution

  • It was a typeshed bug. Issue was created, fixed (not by me), and closed. https://github.com/python/typeshed/issues/11845.