-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Support exhaustive checking for “in” operator. #16593
Draft
Malika1109
wants to merge
38
commits into
python:master
Choose a base branch
from
Malika1109:in-exhaustive-checking
base: master
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.
Draft
Conversation
This file contains 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
…9/mypy into in-exhaustive-checking
This comment has been minimized.
This comment has been minimized.
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
These are all false positives, so the PR has some bugs. |
ab62edd
to
ec1c3d4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…th following format
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
…ore merging and commenting
…ore merging and commenting
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
not needed for PR, since tests should cover this
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Diff from mypy_primer, showing the effect of this PR on open source code: black (https://github.com/psf/black)
+ src/black/__init__.py:530:17: error: Statement is unreachable [unreachable]
+ src/black/__init__.py:835:17: error: Statement is unreachable [unreachable]
+ src/black/concurrency.py:139:9: error: Statement is unreachable [unreachable]
trio (https://github.com/python-trio/trio)
+ src/trio/_dtls.py:367: error: Need type annotation for "messages_by_seq" (hint: "messages_by_seq: Dict[<type>, <type>] = ...") [var-annotated]
mkosi (https://github.com/systemd/mkosi)
+ mkosi/config.py:343:9: error: Statement is unreachable [unreachable]
+ mkosi/qemu.py:428:13: error: Right operand of "or" is never evaluated [unreachable]
+ mkosi/qemu.py:432:13: error: Statement is unreachable [unreachable]
+ mkosi/qemu.py:551:13: error: Statement is unreachable [unreachable]
+ mkosi/distributions/ubuntu.py:27:13: error: Statement is unreachable [unreachable]
+ mkosi/__init__.py:1356:5: error: Statement is unreachable [unreachable]
+ mkosi/__init__.py:1381:5: error: Statement is unreachable [unreachable]
+ mkosi/__init__.py:2309:13: error: Statement is unreachable [unreachable]
+ mkosi/__init__.py:2802:9: error: Statement is unreachable [unreachable]
+ mkosi/__init__.py:2805:5: error: Statement is unreachable [unreachable]
discord.py (https://github.com/Rapptz/discord.py)
- discord/automod.py:316: error: Argument 1 to "_from_value" of "ArrayFlags" has incompatible type "object"; expected "Sequence[int]" [arg-type]
- discord/automod.py:316: error: Argument "allow_list" to "AutoModTrigger" has incompatible type "object"; expected "list[str] | None" [arg-type]
- discord/automod.py:321: error: Argument "mention_limit" to "AutoModTrigger" has incompatible type "object"; expected "int | None" [arg-type]
- discord/automod.py:322: error: Argument "mention_raid_protection" to "AutoModTrigger" has incompatible type "object"; expected "bool | None" [arg-type]
- discord/automod.py:327: error: Missing return statement [return]
+ discord/scheduled_event.py:466: error: Need type annotation for "metadata" (hint: "metadata: Dict[<type>, <type>] = ...") [var-annotated]
- discord/scheduled_event.py:533: error: Incompatible types in assignment (expression has type "None", target has type "str") [assignment]
- discord/scheduled_event.py:555: error: Incompatible types in assignment (expression has type "dict[str, str]", target has type "str") [assignment]
+ discord/scheduled_event.py:555: error: Incompatible types in assignment (expression has type "dict[Any, Any]", target has type "str") [assignment]
+ discord/voice_state.py:278: error: Unused "type: ignore" comment [unused-ignore]
+ discord/voice_state.py:285: error: Unused "type: ignore" comment [unused-ignore]
+ discord/guild.py:2400: error: Unused "type: ignore" comment [unused-ignore]
+ discord/guild.py:3136: error: Need type annotation for "metadata" (hint: "metadata: Dict[<type>, <type>] = ...") [var-annotated]
- discord/guild.py:3209: error: Incompatible types in assignment (expression has type "dict[str, str]", target has type "str") [assignment]
+ discord/guild.py:3209: error: Incompatible types in assignment (expression has type "dict[Any, Any]", target has type "str") [assignment]
+ discord/client.py:2578: error: Unused "type: ignore" comment [unused-ignore]
- discord/app_commands/tree.py:413: error: Missing return statement [return]
- discord/app_commands/tree.py:533: error: Missing return statement [return]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/poolmanager.py:570: error: Argument 1 to "get" of "dict" has incompatible type "str | None"; expected "str" [arg-type]
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/runtime/runtime.py: note: In function "stop":
+ lib/streamlit/runtime/runtime.py:307:13: error: Statement is unreachable [unreachable]
+ lib/streamlit/runtime/runtime.py: note: In member "connect_session" of class "Runtime":
+ lib/streamlit/runtime/runtime.py:371:9: error: Statement is unreachable [unreachable]
+ lib/streamlit/runtime/runtime.py: note: In member "handle_backmsg" of class "Runtime":
+ lib/streamlit/runtime/runtime.py:479:9: error: Statement is unreachable [unreachable]
+ lib/streamlit/runtime/runtime.py: note: In member "handle_backmsg_deserialization_exception" of class "Runtime":
+ lib/streamlit/runtime/runtime.py:509:9: error: Statement is unreachable [unreachable]
+ lib/streamlit/runtime/runtime.py: note: In member "is_ready_for_browser_connection" of class "Runtime":
+ lib/streamlit/runtime/runtime.py:526:13: error: Statement is unreachable [unreachable]
|
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.
This PR attempts to fix #16093
from enum import Enum
from typing import assert_never
class MyEnum(Enum):
A = 1
B = 2
C = 3
def my_function(a: MyEnum) -> bool:
if a == MyEnum.A:
return True
elif a in (MyEnum.B, MyEnum.C):
return False
assert_never(a)
my_function(MyEnum.A)
Earlier the above code would generate the below error:
error: Argument 1 to "assert_never" has incompatible type
"Literal[MyEnum.B, MyEnum.C]"; expected "NoReturn" [arg-type]
assert_never(a)
This PR aims to fix the issue presented in #16093 because creates a separate case for “in” operator to be handled when the right hand side of a comparison expression is TupleExpr.
Through the changes of the pull request my_function passes without any mypy issues:
![Project5-Screenshot](https://private-user-images.githubusercontent.com/68425979/287976884-63c9ab75-753f-4d06-8a4f-0661c69f512b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MDE5MjcsIm5iZiI6MTczOTYwMTYyNywicGF0aCI6Ii82ODQyNTk3OS8yODc5NzY4ODQtNjNjOWFiNzUtNzUzZi00ZDA2LThhNGYtMDY2MWM2OWY1MTJiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDA2NDAyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNmYTczMGRmNDNkN2U3ODc1MThjOGNkYzkzM2VjMDc1MjVjNWU5MDU0OWI1NzM0ZmQ0MDI2MGQ2ZjE0ODc1MDgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.6E2YauQpmkI-IvKizjy11EOZ5eao6UUHwj1Uyp_Pws0)