Skip to content

openpyxl's ReadOnlyWorksheet.__getitem__() cannot be used due to self type mismatching #12200

@InSyncWithFoo

Description

@InSyncWithFoo

Minimal reproducible example:

import openpyxl
from openpyxl.worksheet._read_only import ReadOnlyWorksheet

wb = openpyxl.load_workbook('...', read_only = True)
ws: ReadOnlyWorksheet = wb['foo']

ws[0]
# mypy => error:
# Invalid self argument "ReadOnlyWorksheet" to attribute function "__getitem__"
# with type "Callable[[Worksheet, int], tuple[Cell, ...]]"

The culprit is this assignment:

class ReadOnlyWorksheet:
    ...
    __getitem__ = Worksheet.__getitem__

(From this Stack Overflow question.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions