Skip to content
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

ReadOnlyCell not defined ? #14

Open
johann50 opened this issue Jul 28, 2021 · 1 comment
Open

ReadOnlyCell not defined ? #14

johann50 opened this issue Jul 28, 2021 · 1 comment

Comments

@johann50
Copy link

I can't find where ReadOnlyCell is defined. If I call the
cell function of a worksheet I am getting that the function returns
type "MergedCell** | Unknown | Cell"
because ReadOnlyCell is not defined.

@Avasam
Copy link

Avasam commented May 2, 2024

If you just want the type directly:

https://github.com/python/typeshed/blob/main/stubs/openpyxl/openpyxl/cell/read_only.pyi

from openpyxl.cell.read_only import ReadOnlyCell

also re-exported in:
https://github.com/python/typeshed/blob/main/stubs/openpyxl/openpyxl/cell/__init__.pyi

from openpyxl.cell import ReadOnlyCell

Although even typeshed (https://pypi.org/project/types-openpyxl) doesn't yet support specific cell types per worksheet type: python/typeshed#9940 (comment) & python/typeshed#10952

If you just want to avoid the partial Unknown in pyright, then the typeshed stub will work for you.

If you need the return type to be ReadOnlyCell, for now the best thing is to cast:

from typing import cast
from openpyxl.cell.read_only import ReadOnlyCell

ws: ReadOnlyWorksheet = ...

cell = cast(ReadOnlyCell, ws.cell(1, 1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants