-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
stubs: false positiveType checkers report false errorsType checkers report false errorstopic: collectionsIssues related to collection typesIssues related to collection types
Description
RequestsCookieJar is typed as a subtype of both http.CookieJar and MutableMapping[str, str]:
| class RequestsCookieJar(CookieJar, MutableMapping[str, str]): # type: ignore[misc] # conflicting __iter__ in the base classes |
including a comment ignoring the type error. This is simply wrong; RequestsCookieJar is not a MutableMapping because the __iter__ fn differs.
This causes real problems:
import requests.cookies
import typing
cookiejar = requests.cookies.RequestsCookieJar()
cookiejar["a"] = "b"
print("outside func")
for cookie in cookiejar:
typing.reveal_type(cookie) # type is Cookie at typecheck and runtime
print(f"{type(cookie)=}")
def in_func(not_a_cookiejar:typing.Iterable[str]):
print("in_func")
for maybe_cookie in not_a_cookiejar:
typing.reveal_type(maybe_cookie) # type is str at typecheck
print(f"{type(maybe_cookie)=}") # type is Cookie at runtime
in_func(cookiejar)pyright 1.1.407 says:
information: Type of "cookie" is "Cookie"
information: Type of "maybe_cookie" is "str"
mypy 1.19.1 says:
bad-types.py:9: note: Revealed type is "http.cookiejar.Cookie"
bad-types.py:15: note: Revealed type is "builtins.str"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stubs: false positiveType checkers report false errorsType checkers report false errorstopic: collectionsIssues related to collection typesIssues related to collection types