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

fix(openpyxl): the return type of Workbook.active should be WorkSheet #10597

Closed
wants to merge 1 commit into from

Conversation

iujakchu
Copy link

@iujakchu iujakchu commented Aug 20, 2023

import sys
import openpyxl
def get_prompts(path):
    wb = openpyxl.load_workbook(path)
    sheet = wb.active
    print(type(sheet))
    if sheet is None:
        sys.exit(-1)
    prompts = [cell.value for cell in sheet["C"] if cell.value] #__getitem__ method not defined on type "_WorkbookChild"
    wb.close()
    return prompts

prompts = get_prompts("txt/txt.xlsx")
print(prompts)

the printing shows me that the type of sheet variable is :
<class 'openpyxl.worksheet.worksheet.Worksheet'>
If I understand correctly,the active function should return a WorkSheet or None type.
This pr fixes it.

There is also another setter active function,I have no idea whether should I change it btw.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
Copy link
Collaborator

srittau commented Aug 20, 2023

Unfortunately, changing the return type isn't possible. Previously discussed in #9836 and #10306.

@srittau srittau closed this Aug 20, 2023
@iujakchu
Copy link
Author

Oops,I didn't notice that before.
Thanks for your explanation.

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

Successfully merging this pull request may close these issues.

2 participants