-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fixes for strict-bytes #10454
Fixes for strict-bytes #10454
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
I'm unclear if the remaining errors are a bug with us or with typeshed (which says the method doesn't support |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #10454 +/- ##
=======================================
Coverage 98.69% 98.69%
=======================================
Files 122 122
Lines 37225 37230 +5
Branches 2063 2064 +1
=======================================
+ Hits 36740 36745 +5
Misses 338 338
Partials 147 147
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #10454 will not alter performanceComparing Summary
|
Would you backport the PR |
It changes the (apparent) API, so I'd prefer to avoid it. Hopefully will be focusing on v4 after the typing work I'm doing. |
Up to you, any decision is good to me. |
Yes, focusing on V4 would be good. Personally, I should review the diff and file a list of required changes related to my commits on master that were not backported. |
@bdraco I think you've played with that code fairly recently, any idea if memoryview[bytes] is actually supported? |
asyncio Transport write is typed to so I think only |
We have tests that explicitly use |
I couldn't find any tests where we have def memoryview_bytes(x: "memoryview[bytes]") -> None:
pass
def memoryview_int(x: "memoryview[int]") -> None:
pass
v = memoryview(b"")
memoryview_int(v) # pass
memoryview_bytes(
v
) # error: Argument 1 to "memoryview_bytes" has incompatible type "memoryview[int]"; expected "memoryview[bytes]" [arg-type] |
If you drop bytes from the union, then mypy will flag it up. |
aiohttp/tests/test_http_writer.py Lines 442 to 477 in 982ed47
|
def memoryview_bytes(x: "memoryview[bytes]") -> None:
pass
def memoryview_int(x: "memoryview[int]") -> None:
pass
v = memoryview(b"")
memoryview_int(v) # pass
payload = v.cast("c", [3, 2])
memoryview_bytes(payload) passes now |
So it seems like we support it but aiohttp/aiohttp/http_writer.py Line 106 in 36aa738
aiohttp/aiohttp/http_writer.py Line 108 in 36aa738
I guess it works though since #4890 seems to use it |
Yeah, so typeshed bug then, I'll file a PR there. |
It looks like it gets cast to aiohttp/aiohttp/http_writer.py Line 129 in 36aa738
but So maybe asyncio only supports |
Typeshed updated to |
This will be default behaviour in mypy 2, so best to fix it early.
It would be good if anybody else can check over these, the existing code seems a little confused with when it wants bytes only or will allow bytes/bytearray/memoryview.