Repository navigation
Conversation
Closes python#11470 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11470
Make
urllib.request.Requestgeneric over the type ofdata, soRequest(url, data=b"...").dataisbytesinstead of the full_DataTypeunion, as suggested in the linked issue.There is a trade-off with this implementation though.
A plain
Requestannotation, as used byurlopen(), now meansRequest[Any]. That keepsRequest[bytes]accepted everywhere, but.datais unchecked on code annotated with a plainRequest. Before, it was the union.The alternative I considered but didn't choose is the covariant option, which will also slip through a runtime crash.
I did a small web scrapping to see which option is better and chose the current implementation because the scenario it slips through seem to be rarer (small samples though).
AI Disclosure: I used Claude Opus 5.5 to help resolve this issue.