-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Improve for loop index variable type narrowing #18014
Conversation
This comment has been minimized.
This comment has been minimized.
Mypy primer resultsscrapy + scrapy/downloadermiddlewares/cookies.py:145: error: "str" has no attribute "decode"; maybe "encode"? [attr-defined]
+ scrapy/downloadermiddlewares/cookies.py:152: error: "str" has no attribute "decode"; maybe "encode"? [attr-defined] These are true positives. All TypedDict values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see several now-unnecessary type ignores in mypy_primer output! Looks good, just one minor test-related suggestion.
a = "yearly" | ||
reveal_type(a) # N: Revealed type is "builtins.str" | ||
a = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "str") | ||
reveal_type(a) # N: Revealed type is "builtins.str" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test b = a
followed by reveal_type(b)
.
Diff from mypy_primer, showing the effect of this PR on open source code: pydantic (https://github.com/pydantic/pydantic)
+ pydantic/v1/networks.py:345: error: Unused "type: ignore" comment [unused-ignore]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/downloadermiddlewares/cookies.py:141: error: Unused "type: ignore" comment [unused-ignore]
+ scrapy/downloadermiddlewares/cookies.py:142: error: Unused "type: ignore" comment [unused-ignore]
+ scrapy/downloadermiddlewares/cookies.py:145: error: Unused "type: ignore" comment [unused-ignore]
+ scrapy/downloadermiddlewares/cookies.py:145: error: "str" has no attribute "decode"; maybe "encode"? [attr-defined]
+ scrapy/downloadermiddlewares/cookies.py:145: note: Error code "attr-defined" not covered by "type: ignore" comment
+ scrapy/downloadermiddlewares/cookies.py:152: error: Unused "type: ignore" comment [unused-ignore]
+ scrapy/downloadermiddlewares/cookies.py:152: error: "str" has no attribute "decode"; maybe "encode"? [attr-defined]
+ scrapy/downloadermiddlewares/cookies.py:152: note: Error code "attr-defined" not covered by "type: ignore" comment
discord.py (https://github.com/Rapptz/discord.py)
- discord/message.py:2265: error: TypedDict key must be a string literal; expected one of ("channel_id", "guild_id", "id", "author", "content", ...) [literal-required]
core (https://github.com/home-assistant/core)
+ homeassistant/components/image_processing/__init__.py:226: error: Unused "type: ignore" comment [unused-ignore]
+ homeassistant/components/energy/data.py:334: error: Unused "type: ignore" comment [unused-ignore]
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/cli/__init__.py:260: error: Unused "type: ignore" comment [unused-ignore]
|
Preserve the literal type of index expressions a bit longer (until the next assignment) to support TypedDict lookups.
Closes #9230