-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[stdlib] Make http.cookies.Morsel inherit a TypedDict
#15095
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
Draft
guoci
wants to merge
4
commits into
python:main
Choose a base branch
from
guoci:patch-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Refactor _MorselDictType to conditionally include 'partitioned' field for Python 3.14 and above.
Contributor
|
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]
|
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.
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