Skip to content

Enable warn_unreachable = True for mypyc and all other files as well#19050

Merged
hauntsaninja merged 14 commits intopython:masterfrom
wyattscarpenter:warn_unreachable_in_mypy
Sep 20, 2025
Merged

Enable warn_unreachable = True for mypyc and all other files as well#19050
hauntsaninja merged 14 commits intopython:masterfrom
wyattscarpenter:warn_unreachable_in_mypy

Conversation

@wyattscarpenter
Copy link
Copy Markdown
Contributor

Achieves a todo, enabling warn_unreachable = True for mypyc and all other files as well

@wyattscarpenter
Copy link
Copy Markdown
Contributor Author

wyattscarpenter commented May 8, 2025

I am now waiting on mypyc/mypyc#1101 to be resolved to finish this issue, after which I will have to rebase this branch onto master to get the resolution.

@github-actions

This comment has been minimized.

@sterliakov
Copy link
Copy Markdown
Collaborator

Wow, only one hit? That should be easy to resolve...

@wyattscarpenter
Copy link
Copy Markdown
Contributor Author

wyattscarpenter commented May 10, 2025

@stanislavlevin, yep! Only one hit for this project 🥳! Unfortunately (so to speak), deciding what to do about that is best left to people more familiar with mypyc than me.

I could simply comment out this code, which I might do eventually, but if someone with a better idea about what it should do comes along, I will defer to them.

JukkaL pushed a commit that referenced this pull request Jun 5, 2025
Supplements #19050. The old version did certainly contain unreachable
code, as otherwise that branch would have crashed, there is no
`type_args` attribute. This block was introduced in #17027 - probably as
a future-proof expansion to generic primitive operations, but it makes
no sense now, this logic can be added back should it become necessary.
@github-actions

This comment has been minimized.

@wyattscarpenter
Copy link
Copy Markdown
Contributor Author

Hmm, another hit. I guess it was masked or subsequently developed or something...
Running the self-check on my computer, with python 3.9, doesn't produce this problem, even with --python-version 3.9 🤔. So I guess it's an actual python language behavior change...

@wyattscarpenter
Copy link
Copy Markdown
Contributor Author

wyattscarpenter commented Jun 7, 2025

Even after installing python 3.9 I can't reproduce this. Odd.

I'll try merging again once another commit hits master, in case this was a fluke.

@brianschubert
Copy link
Copy Markdown
Collaborator

Even after installing python 3.9 I can't reproduce this. Odd.

FWIW, I can reproduce this locally in a fresh 3.9 venv:

$ python --version
Python 3.9.23
$ python -m mypy --config-file mypy_self_check.ini misc --exclude misc/sync-typeshed.py
misc/analyze_cache.py:44: error: Statement is unreachable  [unreachable]
                elif isinstance(chunk, list):
                ^
misc/analyze_cache.py:44: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-unreachable for more info
misc/analyze_cache.py:96: error: Statement is unreachable  [unreachable]
                return chunk
                ^~~~~~~~~~~~
misc/analyze_cache.py:127: error: Statement is unreachable  [unreachable]
                return chunk
                ^~~~~~~~~~~~
Found 3 errors in 1 file (checked 17 source files)

I'll try merging again once another commit hits master, in case this was a fluke.

quick git tip: you can also tickle the CI by pushing an empty commit with git commit --allow-empty

@github-actions

This comment has been minimized.

@wyattscarpenter
Copy link
Copy Markdown
Contributor Author

Well, now time has passed and we're down to one different problem, apparently:

mypyc/test/test_cheader.py:35: error: Subclass of "list[PrimitiveDescription]" and "PrimitiveDescription" cannot exist: "PrimitiveDescription" is final  [unreachable]
                    if isinstance(ops, PrimitiveDescription):
                                  ^~~
mypyc/test/test_cheader.py:35: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-unreachable for more info
mypyc/test/test_cheader.py:36: error: Statement is unreachable  [unreachable]
                        ops = [ops]
                        ^~~~~~~~~~~
Found 2 errors in 1 file (checked 313 source files)

@github-actions

This comment has been minimized.

@JukkaL
Copy link
Copy Markdown
Collaborator

JukkaL commented Aug 15, 2025

if isinstance(ops, PrimitiveDescription):

This and the following line can probably be removed, since the isinstance check can never be true.

@sterliakov
Copy link
Copy Markdown
Collaborator

Let's remove that and try to merge this before we introduce another unreachable block:)

JukkaL added a commit that referenced this pull request Aug 15, 2025
JukkaL added a commit that referenced this pull request Aug 15, 2025
@JukkaL
Copy link
Copy Markdown
Collaborator

JukkaL commented Aug 15, 2025

The unreachable code is now removed on master.

@github-actions

This comment has been minimized.

@wyattscarpenter
Copy link
Copy Markdown
Contributor Author

wyattscarpenter commented Aug 15, 2025

Ok, well, now it's back to the isinstance(chunk, list) unreachable error from before.

(Edit: assuming this doesn't clear up on its own by the next time I look into it, I'll probably just throw in a couple type-ignores with TODOs next to them. Better than not having this analysis run at all...)

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@wyattscarpenter wyattscarpenter marked this pull request as ready for review September 19, 2025 07:44
@github-actions
Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

AutoSplit (https://github.com/Toufool/AutoSplit)
-   File "/tmp/mypy_primer/mypy_old/venv/bin/mypy", line 7, in <module>
+   File "/tmp/mypy_primer/mypy_new/venv/bin/mypy", line 7, in <module>
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/main.py", line 127, in main
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/main.py", line 127, in main
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/main.py", line 211, in run_build
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/main.py", line 211, in run_build
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/build.py", line 196, in build
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/build.py", line 196, in build
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/build.py", line 272, in _build
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/build.py", line 272, in _build
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/build.py", line 2946, in dispatch
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/build.py", line 2946, in dispatch
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/build.py", line 3346, in process_graph
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/build.py", line 3346, in process_graph
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/build.py", line 3475, in process_stale_scc
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/build.py", line 3475, in process_stale_scc
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/build.py", line 2493, in write_cache
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/build.py", line 2493, in write_cache
-   File "/tmp/mypy_primer/mypy_old/venv/lib/python3.13/site-packages/mypy/cache.py", line 28, in __init__
+   File "/tmp/mypy_primer/mypy_new/venv/lib/python3.13/site-packages/mypy/cache.py", line 28, in __init__

Copy link
Copy Markdown
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hauntsaninja hauntsaninja merged commit e1aada8 into python:master Sep 20, 2025
20 checks passed
@wyattscarpenter wyattscarpenter deleted the warn_unreachable_in_mypy branch September 21, 2025 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants