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

Use Literal type in io and _compression #6917

Merged
merged 3 commits into from
Jan 14, 2022
Merged

Use Literal type in io and _compression #6917

merged 3 commits into from
Jan 14, 2022

Conversation

sobolevn
Copy link
Member

No description provided.

@JelleZijlstra
Copy link
Member

Just curious, what is your motivation for all these Literal changes? Is there a concrete use case this unlocks?

@JelleZijlstra JelleZijlstra merged commit 74d043b into python:master Jan 14, 2022
@github-actions
Copy link
Contributor

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

@sobolevn
Copy link
Member Author

Just curious, what is your motivation for all these Literal changes? Is there a concrete use case this unlocks?

Yes, I am working on better Literal type support in mypy. The first issue is already there: python/mypy#11992

@JelleZijlstra
Copy link
Member

I saw that but I wasn't clear on the concrete use case there either.

@Akuli
Copy link
Collaborator

Akuli commented Jan 14, 2022

I can see myself staring at some code that works incorrectly with a chunk of data that is 10000 bytes long but fine with 5000 bytes, wondering what io.DEFAULT_BUFFER_SIZE is, and bringing my mouse over it to see a tooltip describing it. It would be convenient to just see the actual value.

@sobolevn
Copy link
Member Author

@JelleZijlstra I think that this is how typing should be 🙂

It is just happens right now that we don't use Literal that much in Python, mostly because of the legacy. But, I think that at some point we can reach this behavior in mypy:

x = 1
reveal_type(x) # Literal[1]

I think that what pyright does at the moment.
And this will make literal math a very handy feature!

@a-reich
Copy link

a-reich commented Jan 16, 2022

There has been discussion of using literal arithmetic to type array operations (for the shape parameter).

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.

None yet

4 participants