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

An enhancement for type hinting #125602

Closed
Unknownuserfrommars opened this issue Oct 16, 2024 · 4 comments
Closed

An enhancement for type hinting #125602

Unknownuserfrommars opened this issue Oct 16, 2024 · 4 comments
Labels
topic-typing type-feature A feature request or enhancement

Comments

@Unknownuserfrommars
Copy link

Unknownuserfrommars commented Oct 16, 2024

Feature or enhancement

Proposal:

So type hinting is GREAT. Don't get me wrong, but that is ACTUALLY THE BEST THING PYTHON EVER HAD AND NO KIDDING.
But then, type hints can't deal with cases like this:

def bundle(what_ever_kwargs) -> list[dict*8]:
pass

So this is not supported. But to be PRECISE, we want to state that this function EXACTLY RETURNS 8 dictionaries.
So can we add support for this kind of type hinting (in 3.14 maybe?)

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

@Unknownuserfrommars Unknownuserfrommars added the type-feature A feature request or enhancement label Oct 16, 2024
@zware
Copy link
Member

zware commented Oct 16, 2024

Please open a discussion on Discourse for this.

@zware zware closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2024
@sobolevn
Copy link
Member

@Unknownuserfrommars in the meantime you can use tuple[dict, dict, dict, dict, dict, dict, dict, dict] as a type that returns exactly 8 dicts :)

@JelleZijlstra
Copy link
Member

See also python/typing#786. If you think this is an important feature, read that discussion and prepare a PEP to add it to the type system. (Personally I'm not sure it's worth the extra complexity.)

@nineteendo
Copy link
Contributor

This works at runtime, but mypy doesn't understand it:
https://mypy-play.net/?mypy=latest&python=3.12&gist=b8c2f957417f3600cb34563b200adb02

>>> list[(dict,) * 8]
list[dict, dict, dict, dict, dict, dict, dict, dict]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants