-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Invalid type definition for mpwriter.append #7741
Copy link
Copy link
Closed
Labels
Description
Describe the bug
It would appear that the append method of the MultiPartWriter has an incorrect type definition:
Line 856 in d8936aa
| def append(self, obj: Any, headers: Optional[MultiMapping[str]] = None) -> Payload: |
Resulting in type checking tools to incorrectly errpr what (I believe) should be correct.
To Reproduce
The following test file generates the error in type checkers.
import aiohttp
with aiohttp.MultipartWriter() as mpwriter:
mpwriter.append("Hello, World", {"Content-Type": "text/plain"})which generates the following errors:
❯ mypy test.py
test.py:4: error: Argument 2 to "append" of "MultipartWriter" has incompatible type "dict[str, str]"; expected "MultiMapping[str] | None" [arg-type]
Found 1 error in 1 file (checked 1 source file)
❯ pyright test.py
/Users/joshua.ellis/src/pact-foundation/pact-python/tests/v3/test.py
/Users/joshua.ellis/src/pact-foundation/pact-python/tests/v3/test.py:4:37 - error: Argument of type "dict[str, str]" cannot be assigned to parameter "headers" of type "MultiMapping[str] | None" in function "append"
Type "dict[str, str]" cannot be assigned to type "MultiMapping[str] | None"
"dict[str, str]" is incompatible with "MultiMapping[str]"
Type cannot be assigned to type "None" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informationsExpected behavior
I expected that a regular Python dictionary be compatible with the header argument.
Logs/tracebacks
_see above_Python Version
❯ python --version
Python 3.11.6aiohttp Version
❯ python -m pip show aiohttp
Name: aiohttp
Version: 3.8.6
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Requires: aiosignal, async-timeout, attrs, charset-normalizer, frozenlist, multidict, yarl
Required-by:multidict Version
❯ python -m pip show multidict
Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Requires:
Required-by: aiohttp, yarlyarl Version
❯ python -m pip show yarl
Name: yarl
Version: 1.9.2
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache-2.0
Requires: idna, multidict
Required-by: aiohttpOS
❯ uname -mprs
Darwin 22.6.0 arm64 armRelated component
Client
Additional context
No response
Code of Conduct
- I agree to follow the aio-libs Code of Conduct
Reactions are currently unavailable