typeshed
typeshed copied to clipboard
[stdlib] Make `http.cookies.Morsel` inherit a `TypedDict`
docs: https://docs.python.org/3/library/http.cookies.html#http.cookies.Morsel.expires src: https://github.com/python/cpython/blob/77399436bfc87663f9058b749b6cb598bab273f9/Lib/http/cookies.py#L257-L268
Diff from mypy_primer, showing the effect of this PR on open source code:
tornado (https://github.com/tornadoweb/tornado)
+ tornado/web.py:644: error: "Morsel[Any]" has no attribute "value" [attr-defined]
+ tornado/web.py:709: error: TypedDict "Morsel[str]" has no key "max-age" [typeddict-unknown-key]
+ tornado/web.py:709: note: Did you mean "max_age"?
+ tornado/web.py:723: error: TypedDict key must be a string literal; expected one of ("expires", "path", "comment", "domain", "max_age", ...) [literal-required]
+ tornado/web.py:1222: error: "Morsel[str]" has no attribute "OutputString" [attr-defined]
+ tornado/test/web_test.py:595: error: "Morsel[Any]" has no attribute "value" [attr-defined]
+ tornado/test/httpserver_test.py:319: error: "Morsel[Any]" has no attribute "value" [attr-defined]
dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ddtrace/appsec/_http_utils.py:79: error: "Morsel[str]" has no attribute "value" [attr-defined]
starlette (https://github.com/encode/starlette)
+ starlette/responses.py:106: error: TypedDict "Morsel[str]" has no key "max-age" [typeddict-unknown-key]
+ starlette/responses.py:106: note: Did you mean "max_age"?
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/curl.py:68: error: "Morsel[str]" has no attribute "value" [attr-defined]
+ scrapy/utils/curl.py:78: error: "Morsel[str]" has no attribute "value" [attr-defined]
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/cli/commands/run/handlers/cassettes.py: note: In function "_cookie_to_har":
+ src/schemathesis/cli/commands/run/handlers/cassettes.py:459: error: "Morsel[str]" has no attribute "value" [attr-defined]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/_cookie_helpers.py:104:47: error: "Morsel[str]" has no attribute "key" [attr-defined]
+ aiohttp/_cookie_helpers.py:104:59: error: Missing keys ("expires", "path", "comment", "domain", "max_age", "secure", "httponly", "version", "samesite", "__str__") for TypedDict "Morsel[_T]" [typeddict-item]
+ aiohttp/_cookie_helpers.py:104:59: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-typeddict-item for more info
+ aiohttp/_cookie_helpers.py:110:17: error: "Morsel[str]" has no attribute "key" [attr-defined]
+ aiohttp/_cookie_helpers.py:110:38: error: "Morsel[str]" has no attribute "value" [attr-defined]
+ aiohttp/_cookie_helpers.py:110:67: error: "Morsel[str]" has no attribute "coded_value" [attr-defined]
+ aiohttp/_cookie_helpers.py:209:30: error: Missing keys ("expires", "path", "comment", "domain", "max_age", "secure", "httponly", "version", "samesite", "__str__") for TypedDict "Morsel[_T]" [typeddict-item]
+ aiohttp/_cookie_helpers.py:229:18: error: Missing keys ("expires", "path", "comment", "domain", "max_age", "secure", "httponly", "version", "samesite", "__str__") for TypedDict "Morsel[_T]" [typeddict-item]
+ aiohttp/_cookie_helpers.py:295:40: error: TypedDict key must be a string literal; expected one of ("expires", "path", "comment", "domain", "max_age", ...) [literal-required]
+ aiohttp/_cookie_helpers.py:295:40: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-literal-required for more info
+ aiohttp/_cookie_helpers.py:302:55: error: "Morsel[str]" has no attribute "isReservedKey" [attr-defined]
+ aiohttp/_cookie_helpers.py:303:40: error: TypedDict key must be a string literal; expected one of ("expires", "path", "comment", "domain", "max_age", ...) [literal-required]
+ aiohttp/_cookie_helpers.py:309:36: error: TypedDict key must be a string literal; expected one of ("expires", "path", "comment", "domain", "max_age", ...) [literal-required]
+ aiohttp/_cookie_helpers.py:320:38: error: Missing keys ("expires", "path", "comment", "domain", "max_age", "secure", "httponly", "version", "samesite", "__str__") for TypedDict "Morsel[_T]" [typeddict-item]
+ aiohttp/_cookie_helpers.py:326: error: Unused "type: ignore" comment [unused-ignore]
+ aiohttp/_cookie_helpers.py:326:21: error: Item "Morsel[str]" of "Morsel[str] | Any" has no attribute "__setstate__" [union-attr]
+ aiohttp/_cookie_helpers.py:326:21: note: Error code "union-attr" not covered by "type: ignore" comment
+ aiohttp/_cookie_helpers.py:326:21: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-union-attr for more info
+ aiohttp/helpers.py:1004:19: error: Key "expires" of TypedDict "Morsel[str]" cannot be deleted [misc]
+ aiohttp/helpers.py:1010:15: error: TypedDict "Morsel[str]" has no key "max-age" [typeddict-unknown-key]
+ aiohttp/helpers.py:1010:15: note: Did you mean "max_age"?
+ aiohttp/helpers.py:1010:15: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-typeddict-unknown-key for more info
+ aiohttp/helpers.py:1012:19: error: TypedDict "Morsel[str]" has no key "max-age" [typeddict-item]
+ aiohttp/helpers.py:1012:19: note: Did you mean "max_age"?
+ aiohttp/helpers.py:1024:15: error: TypedDict "Morsel[str]" has no key "partitioned" [typeddict-unknown-key]
+ aiohttp/helpers.py:1027:33: error: "Morsel[str]" has no attribute "output" [attr-defined]
+ aiohttp/helpers.py:1067:17: error: "Morsel[str]" has no attribute "output" [attr-defined]
+ aiohttp/cookiejar.py:233:20: error: Cannot use isinstance() with TypedDict type [misc]
+ aiohttp/cookiejar.py:241:27: error: Value of type "Any | object" is not indexable [index]
+ aiohttp/cookiejar.py:241:27: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-index for more info
+ aiohttp/cookiejar.py:243:28: error: Key "domain" of TypedDict "Morsel[str]" cannot be deleted [misc]
+ aiohttp/cookiejar.py:243:28: error: Argument 1 to "__delitem__" of "TypedDict" has incompatible type "str"; expected "Never" [arg-type]
+ aiohttp/cookiejar.py:249:26: error: Unsupported target for indexed assignment ("Morsel[str] | Morsel[Any]") [index]
+ aiohttp/cookiejar.py:251:27: error: Value of type "Any | object" is not indexable [index]
+ aiohttp/cookiejar.py:253:26: error: Value of type "Any | object" is not indexable [index]
+ aiohttp/cookiejar.py:254:17: error: Unsupported target for indexed assignment ("Morsel[str] | Morsel[Any]") [index]
+ aiohttp/cookiejar.py:256:55: error: Argument 1 to "_is_domain_match" of "CookieJar" has incompatible type "Any | object"; expected "str" [arg-type]
+ aiohttp/cookiejar.py:261:28: error: Value of type "Any | object" is not indexable [index]
+ aiohttp/cookiejar.py:269:17: error: Unsupported target for indexed assignment ("Morsel[str] | Morsel[Any]") [index]
+ aiohttp/cookiejar.py:270:20: error: Item "object" of "Any | object" has no attribute "rstrip" [union-attr]
+ aiohttp/cookiejar.py:272:34: error: TypedDict "Morsel[str]" has no key "max-age" [typeddict-item]
+ aiohttp/cookiejar.py:272:34: note: Did you mean "max_age"?
+ aiohttp/cookiejar.py:274:41: error: Argument 1 to "int" has incompatible type "Any | object"; expected "str | Buffer | SupportsInt | SupportsIndex | SupportsTrunc" [arg-type]
+ aiohttp/cookiejar.py:276:61: error: Argument 2 to "_expire_cookie" of "CookieJar" has incompatible type "Any | object"; expected "str" [arg-type]
+ aiohttp/cookiejar.py:278:21: error: Unsupported target for indexed assignment ("Morsel[str] | Morsel[Any]") [index]
+ aiohttp/cookiejar.py:278:28: error: TypedDict "Morsel[str]" has no key "max-age" [typeddict-unknown-key]
+ aiohttp/cookiejar.py:278:28: note: Did you mean "max_age"?
+ aiohttp/cookiejar.py:281:52: error: Argument 1 to "_parse_date" of "CookieJar" has incompatible type "Any | object"; expected "str" [arg-type]
+ aiohttp/cookiejar.py:282:54: error: Argument 2 to "_expire_cookie" of "CookieJar" has incompatible type "Any | object"; expected "str" [arg-type]
+ aiohttp/cookiejar.py:284:21: error: Unsupported target for indexed assignment ("Morsel[str] | Morsel[Any]") [index]
+ aiohttp/cookiejar.py:287:30: error: Invalid index type "tuple[Any | object, Any]" for "defaultdict[tuple[str, str], SimpleCookie]"; expected type "tuple[str, str]" [index]
+ aiohttp/cookiejar.py:290:31: error: Invalid index type "tuple[Any | object, Any]" for "defaultdict[tuple[str, str], SimpleCookie]"; expected type "tuple[str, str]" [index]
+ aiohttp/cookiejar.py:290:44: error: Incompatible types in assignment (expression has type "Morsel[str] | Morsel[Any]", target has type "str | Morsel[str]") [assignment]
+ aiohttp/cookiejar.py:291:36: error: Invalid index type "tuple[Any | object, Any]" for "defaultdict[tuple[str, str], dict[str, Morsel[str]]]"; expected type "tuple[str, str]" [index]
+ aiohttp/cookiejar.py:327:16: error: "Morsel[str]" has no attribute "key" [attr-defined]
+ aiohttp/cookiejar.py:328:26: error: "Morsel[str]" has no attribute "key" [attr-defined]
+ aiohttp/cookiejar.py:333:37: error: "Morsel[str]" has no attribute "key" [attr-defined]
+ aiohttp/cookiejar.py:334:22: error: "Morsel[str]" has no attribute "key" [attr-defined]
+ aiohttp/cookiejar.py:383:35: error: "Morsel[str]" has no attribute "coded_value" [attr-defined]
+ aiohttp/cookiejar.py:385:31: error: Missing keys ("expires", "path", "comment", "domain", "max_age", "secure", "httponly", "version", "samesite", "__str__") for TypedDict "Morsel[_T]" [typeddict-item]
+ aiohttp/cookiejar.py:387:62: error: "Morsel[str]" has no attribute "value" [attr-defined]
+ aiohttp/cookiejar.py:389:35: error: "Morsel[str]" has no attribute "value" [attr-defined]
+ aiohttp/client_reqrep.py:307:17: error: "Morsel[str]" has no attribute "OutputString" [attr-defined]
+ aiohttp/web_request.py:574:40: error: "Morsel[str]" has no attribute "value" [attr-defined]
This seems not to work, according to: https://github.com/python/mypy/issues/4201 Closing.