Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Avoid falseunreachable andredundant-expr warnings in loops more robustly and efficiently, and avoid multiplerevealed type notes for the same line.#19118

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tyralla wants to merge5 commits intopython:master
base:master
Choose a base branch
Loading
fromtyralla:fix/reachability_regression

Conversation

tyralla
Copy link
Collaborator

Fixes#18606
Closes#18511
Improves#18991

This change is an improvement over9685171. Besides fixing the regression reported in#18606 and removing the duplicates reported in#18511, it should significantly reduce the performance regression reported in#18991. At least runningMeasure-command {python runtests.py self} on my computer (with removed cache) is 10 % faster.

tyrallaand others added2 commitsMay 20, 2025 07:12
… robustly and efficiently, and avoid multiple `revealed type` notes for the same line.This change is an improvement over9685171.  Besides fixing the regression reported inpython#18606 and removing the duplicates reported inpython#18511, it should significantly reduce the performance regression reported inpython#18991.  At least running `Measure-command {python runtests.py self}` on my computer (with removed cache) is 10 % faster.
@github-actionsGitHub Actions

This comment has been minimized.

@tyrallatyralla requested a review fromJukkaLMay 20, 2025 06:58
@tyralla
Copy link
CollaboratorAuthor

@JukkaL: I thought that later responses toreveal_type are always better than earlier ones. However, this is not the case fortestNewRedefineTryStatement test case. Maybe the most general approach would be to collect all the union items of the individual responses and to combine them in the final note. I could try this, if you think it's a good way to go.

Alternatively, I could just remove thereveal_type part of this pull request, as it seems less important than the other two addressed issues.

@github-actionsGitHub Actions
Copy link
Contributor

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

xarray (https://github.com/pydata/xarray)+ xarray/conventions.py:413: error: Argument "decode_timedelta" to "decode_cf_variable" has incompatible type "object"; expected "bool | CFTimedeltaCoder | None"  [arg-type]

@tyralla
Copy link
CollaboratorAuthor

I implemented a collection mechanism for the types revealed in different iteration steps. In the case of unions, the items are sorted alphabetically without differentiating upper and lower case letters.

At first glance, the reason for the Mypy primer diff (https://github.com/pydata/xarray) is not clear to me.

I asked for a review of those who opened the mentioned issues. Thanks in advance!

@sterliakov
Copy link
Collaborator

xarray is#19121, we have it on all current PRs

@tyralla
Copy link
CollaboratorAuthor

@sterliakov: Thanks, good to know. (Anybody already working on it?)

@sterliakov
Copy link
Collaborator

@tyralla I'm a bit swamped, there are no related PRs open - so probably not yet? It is likely related to#18976, but I have no idea why it's inconsistent - any MRE extracted from that fails every time, not randomly.https://mypy-play.net/?mypy=master&python=3.12&flags=strict&gist=50f4ae811a650f9e90c6f52269f59d29

Copy link
Collaborator

@A5rocksA5rocks left a comment

Choose a reason for hiding this comment

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

I'm not immediately convinced this is robust!

# We collect errors that indicate unreachability or redundant expressions
# in the first iteration and remove them in subsequent iterations if the
# related statement becomes reachable or non-redundant due to changes in
# partial types:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if an unreachable statement is within another unreachable statement?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

I am not exactly sure what you are asking for.

Is this an example that fits your question?

[casetestAvoidUnreachableCodeInUnreachableCodeWithPartialType]# flags: --warn-unreachable --python-version 3.11x=Noney=NonewhilexisNoneandyisNone:reveal_type(x)# N: Revealed type is "None"reveal_type(y)# N: Revealed type is "None"ifxisNoneandyisnotNone:x=1# E: Statement is unreachableifyisNone:y=1[builtinsfixtures/bool.pyi]

In this case, the results are the same for 1.15 and the current state of this PR.

@tyralla
Copy link
CollaboratorAuthor

I'm not immediately convinced this is robust!

What kind of test case could convince you?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@A5rocksA5rocksA5rocks left review comments

@JukkaLJukkaLAwaiting requested review from JukkaL

@hauntsaninjahauntsaninjaAwaiting requested review from hauntsaninja

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[1.15 regression] (Temporary) false positive for reachability with unannotated partial type mypy duplicatesreveal_type notes with partial types
3 participants
@tyralla@sterliakov@A5rocks

[8]ページ先頭

©2009-2025 Movatter.jp