Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve annotation for tabular_data parameter of tabulate.tabulate #13178

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

Merged
merged 4 commits into from
Dec 6, 2024

Conversation

kaibr
Copy link
Contributor

@kaibr kaibr commented Dec 3, 2024

The type of keys does not matter when a dict of columns is passed to tabulate.

In particular, I have a case where I pass a dict with int keys, and it works fine, but is flagged by mypy.

This comment has been minimized.

@AlexWaygood AlexWaygood changed the title Relax type of keys Improve annotation for tabular_data parameter of tabulate.tabulate Dec 3, 2024
@srittau
Copy link
Collaborator

srittau commented Dec 3, 2024

The significant line is here: https://github.com/astanin/python-tabulate/blob/537d7b03932263062d37a7e747f19a385709b9f7/tabulate/__init__.py#L1502

So technically any value is supported as key, so object would be correct. But I don't think this is helpful. Instead, we should use Any as key with a comment what the expectations for keys are.

@kaibr
Copy link
Contributor Author

kaibr commented Dec 3, 2024

Why would you use Any if object can be used?

What expectation/comment did you have in mind?

@JelleZijlstra
Copy link
Member

Since Mapping is invariant in the key type, using object as the key type is likely inconvenient for many users.

@kaibr
Copy link
Contributor Author

kaibr commented Dec 4, 2024

I wasn't aware of the invariance... Thanks for your patience @srittau and @JelleZijlstra.

I'm not sure about a potential comment wrt. the expectations on the key type. Since str can be called on any object there aren't any I'm aware of.

This comment has been minimized.

Co-authored-by: Sebastian Rittau <[email protected]>
Copy link
Contributor

github-actions bot commented Dec 5, 2024

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

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit 98f070a into python:main Dec 6, 2024
48 checks passed
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.

3 participants