Skip to content

Check functions with constrained type variable parameters for unreachability.#20485

Open
tyralla wants to merge 4 commits intopython:masterfrom
tyralla:feature/unreachable_type_var_constraints
Open

Check functions with constrained type variable parameters for unreachability.#20485
tyralla wants to merge 4 commits intopython:masterfrom
tyralla:feature/unreachable_type_var_constraints

Conversation

@tyralla
Copy link
Collaborator

@tyralla tyralla commented Dec 29, 2025

Fixes #19256
(and removes some to-do comments)

We implemented all the logic in previous PRs for loops and finally clauses. This PR just activates the available features for functions (for performance reasons, only if there are at least two expansions).

I decided against grouping separate responses to revealed_type for individual expansions into unions, which would be more confusing than helpful in my opinion, and so also added the IterationErrorWatcher.collect_revealed_types option.

…ability.

Fixes python#19256
(and removes some to-do comments)

We implemented all the logic in previous PRs for loops and finally clauses.  This PR just activates the available features for functions (for performance reasons, only if there are at least two expansions).

I decided against grouping separate responses to `revealed_type` for individual expansions into unions, which would be more confusing than helpful in my opinion, and so also added the `IterationErrorWatcher.collect_revealed_types` option.
@github-actions

This comment has been minimized.

@tyralla
Copy link
Collaborator Author

tyralla commented Dec 29, 2025

As far as I can tell, nearly all of the primer results are improvements. The one I am most uncertain of is the one concerning rotkehlchen. I think this is a false positive triggered by the Walrus operator somehow.

Performance measurements:

master                    13.180s (0.0%) | stdev 3.164s
feature/unreachable_type_var_constraints 12.619s (-4.3%) | stdev 3.167s
Total time taken by the whole benchmarking program (including any setup): 17 minutes, 20 seconds

master                    7.683s (0.0%) | stdev 0.189s
feature/unreachable_type_var_constraints 7.779s (+1.2%) | stdev 0.255s
Total time taken by the whole benchmarking program (including any setup): 10 minutes, 59 seconds

master                    8.048s (0.0%) | stdev 0.184s
feature/unreachable_type_var_constraints 8.084s (+0.5%) | stdev 0.208s
Total time taken by the whole benchmarking program (including any setup): 13 minutes, 47 seconds

@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Mar 11, 2026

@hauntsaninja As you have been working on reachability recently, could you please check this one?

@github-actions
Copy link
Contributor

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

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/templating.py:249: error: Redundant cast to "list[Any]"  [redundant-cast]

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/http_parser.py:259:20: error: Non-overlapping equality check (left operand type: "bytes", right operand type: "Literal['\r\n']")  [comparison-overlap]
+ aiohttp/http_parser.py:259:20: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-comparison-overlap for more info

altair (https://github.com/vega/altair)
- altair/vegalite/v6/api.py:1182: error: Redundant cast to "_Conditional[list[_ConditionClosed]]"  [redundant-cast]

operator (https://github.com/canonical/operator)
- ops/pebble.py:1854: error: Redundant cast to "str"  [redundant-cast]
- ops/pebble.py:1855: error: Redundant cast to "str"  [redundant-cast]

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/node_iter.py:131: error: Statement is unreachable  [unreachable]
+ static_frame/core/node_iter.py:168: error: Statement is unreachable  [unreachable]
+ static_frame/core/node_iter.py:350: error: Subclass of "Series[Any, Any]" and "Yarn[Any]" cannot exist: have distinct disjoint bases  [unreachable]
+ static_frame/core/node_iter.py:350: error: Subclass of "Frame[Any, Any, *tuple[Any, ...]]" and "Bus[Any]" cannot exist: have distinct disjoint bases  [unreachable]
+ static_frame/core/node_iter.py:350: error: Subclass of "Series[Any, Any]" and "Bus[Any]" cannot exist: have distinct disjoint bases  [unreachable]
+ static_frame/core/node_iter.py:350: error: Subclass of "Frame[Any, Any, *tuple[Any, ...]]" and "Yarn[Any]" cannot exist: have distinct disjoint bases  [unreachable]
+ static_frame/core/node_iter.py:354: error: Statement is unreachable  [unreachable]

xarray (https://github.com/pydata/xarray)
+ xarray/core/dtypes.py:74: error: Unused "type: ignore" comment  [unused-ignore]
+ xarray/core/groupby.py:1047: error: Unused "type: ignore" comment  [unused-ignore]

@tyralla
Copy link
Collaborator Author

tyralla commented Mar 11, 2026

@hauntsaninja As you have been working on reachability recently, could you please check this one?

Make sense. The little adjustment to let all tests pass again after merging was actually made necessary by #20488...

Thanks in advance to whoever wants to have a look at it!

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.

Unreachability should work for constrained type vars

2 participants