GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support exhaustive checking for “in” operator. by Malika1109 · Pull Request #16593 · python/mypy

Conversation

@Malika1109

@Malika1109 Malika1109 commented Dec 1, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Malika1109 and others added 4 commits December 1, 2023 07:27
@Malika1109
Creating if branch to check for TupleExpr
bd3c60a
@Malika1109
Checking if all elements iin the TupleExpr are enums
8a0aee6
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
23d13f9
for more information, see https://pre-commit.ci
@Malika1109
Fixed indent issues
f73e3fa
@Malika1109
Malika1109 marked this pull request as draft December 1, 2023 04:48
@Malika1109
Merge branch 'in-exhaustive-checking' of https://github.com/Malika110…
aaec558
…9/mypy into in-exhaustive-checking
@github-actions

This comment has been minimized.

Sign in to view
Malika1109 and others added 2 commits December 1, 2023 08:21
@Malika1109
Modified operators.py
e14adcb
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
018cf15
for more information, see https://pre-commit.ci
@github-actions

This comment has been minimized.

Sign in to view
Malika1109 added 4 commits December 1, 2023 09:36
@Malika1109
Fixed formatting issues
38102c7
@Malika1109
Merge branch 'master' into in-exhaustive-checking
a3fb558
@Malika1109
Merging purposes commit
cd9826c
@Malika1109
Merging purposes commit
ec1c3d4
@github-actions

This comment has been minimized.

Sign in to view
@JelleZijlstra

JelleZijlstra commented Dec 1, 2023

Copy link
Copy Markdown
Member
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]

These are all false positives, so the PR has some bugs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Malika1109
Malika1109 force-pushed the in-exhaustive-checking branch from ab62edd to ec1c3d4 Compare December 1, 2023 18:21
Malika1109 and others added 6 commits December 1, 2023 21:32
@Malika1109
Resolved merge conflicts in typinig_extensions.pyi
526f430
@Malika1109
Resolved merge conflicts in typinig_extensions.pyi
605f66c
@Malika1109
Merge pull request #1 from python/master
c70b3f1
Merging latest changes to mypy
@Malika1109
Resolved formatting issues
b56ab60
@Malika1109
Merge branch 'master' of https://github.com/Malika1109/mypy into in-e…
8116d9f
…xhaustive-checking
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
090bc6f
for more information, see https://pre-commit.ci
@github-actions

This comment has been minimized.

Sign in to view
@Malika1109
Modified pyproject.tomll for ruff error
2df876c
@github-actions

This comment has been minimized.

Sign in to view
Malika1109 and others added 4 commits December 4, 2023 09:21
@Malika1109
Made changes to handling of in for open-source errors
4a9e582
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
9bd590e
for more information, see https://pre-commit.ci
@Malika1109
Changed handling of in operator
6dd351c
@Malika1109
Changed handling of in operator
17e1b7e
@github-actions

This comment has been minimized.

Sign in to view
a-khaldi and others added 3 commits December 5, 2023 08:47
@a-khaldi
successfully created the check-in-exhaustive-checking-3.test file for…
30b6cae
… extra testing
@a-khaldi
removed the 3 in the name of the file for clarity + began the test wi…
fc611bc
…th following format
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
4d38b0b
for more information, see https://pre-commit.ci
@github-actions

This comment has been minimized.

Sign in to view
a-khaldi and others added 3 commits December 5, 2023 09:45
@a-khaldi
testing is done without any comments, want to make sure it passes bef…
4420ed8
…ore merging and commenting
@a-khaldi
testing is done without any comments, want to make sure it passes bef…
652caa4
…ore merging and commenting
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
b4bf17a
for more information, see https://pre-commit.ci
@github-actions

This comment has been minimized.

Sign in to view
@ssaloos
removed unneeded comments & code
55d3b2f
@github-actions

This comment has been minimized.

Sign in to view
@GulnazSerikbay
Delete feature-test.py for PR
16ca296
not needed for PR, since tests should cover this
@github-actions

This comment has been minimized.

Sign in to view
Maha Alnassr
added comments for clarity and minor changes to in exhaustive checkin…
e7694a8
…g test file
@github-actions

This comment has been minimized.

Sign in to view
GulnazSerikbay and others added 7 commits December 6, 2023 22:16
@GulnazSerikbay
added some enum type extraction + test
64a8ab5
@GulnazSerikbay
Merge branch
6973a96
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
5a060f7
for more information, see https://pre-commit.ci
@GulnazSerikbay
small fix
8144105
@GulnazSerikbay
merge for pull and push
69aec40
@GulnazSerikbay
removed some code
046370e
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
06c8d98
for more information, see https://pre-commit.ci
@github-actions

github-actions Bot commented Dec 6, 2023

Copy link
Copy Markdown
Contributor

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]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja

hauntsaninja commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Thanks, this logic has been rewritten a few times since this PR, #21456 and preceding PRs fix the relevant issue

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hauntsaninja hauntsaninja closed this May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Support exhaustiveness checking for 'in' statements (enums)

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@Malika1109 @JelleZijlstra @hauntsaninja @a-khaldi @ssaloos @GulnazSerikbay
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.