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

[Feature Request / Question] Minimum length List / Sequence #8501

Closed
ayroblu opened this issue Mar 6, 2020 · 5 comments
Closed

[Feature Request / Question] Minimum length List / Sequence #8501

ayroblu opened this issue Mar 6, 2020 · 5 comments

Comments

@ayroblu
Copy link

ayroblu commented Mar 6, 2020

Hi I was wondering if it's possible to create a List/Sequence type with a minimum length
I work with TypeScript a lot too and here's an example TS example: https://stackoverflow.com/questions/49910889/typescript-array-with-minimum-length
(this uses some of the oddities of JavaScript to achieve this I guess)

So I'd like to have an my_list = AtLeastOneList[str] which will fail the type check on my_list[0]

Just wondering if it's possible!

@JelleZijlstra
Copy link
Member

This isn't supported by the current type system, and I don't think there are any currently planned features that would allow it.

@ilevkivskyi
Copy link
Member

I am keeping this open for now because theoretically we can think about overloading __getitem__() on literal values. But this is very low priority, so don't be surprised if it will be ultimately closed.

@ayroblu
Copy link
Author

ayroblu commented Mar 6, 2020 via email

@AlexWaygood
Copy link
Member

Similar idea to #8441

@hauntsaninja
Copy link
Collaborator

This would require a new type system feature, so should be discussed at https://github.com/python/typing, possibly at python/typing#786

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants