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

prevent false unreachable warnings for @final instances that occur when strict optional checking is disabled#20045

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

Conversation

@tyralla
Copy link
Collaborator

Fixes#19849

See#11717 for some background information on--no-strict-optional.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@sterliakovsterliakov left a comment

Choose a reason for hiding this comment

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

Primer change looks correct to me,result is defined earlier at L470 to an incompatible type. This branch was apparently unreachable before this change.

@tyralla
Copy link
CollaboratorAuthor

Yes, I think you are right. Mypy thought the branch was unreachable becauseEQUAL_NULL_PATTERN.match(constraint) returnsMatch | None, which it interprets asMatch because of--no-strict-optional.

@ilevkivskyi: Not a super critical bug, but at least a super simple fix. Could you take a look at it?

returnUninhabitedType(line=t.line)
elifisinstance(t,Instance):
ift.type.is_finalort.type.is_enum:
if(t.type.is_finalort.type.is_enum)andstate.strict_optional:
Copy link
Member

Choose a reason for hiding this comment

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

I think this should apply to the branch just below as well. I mean what if in your test you will havex: Optional[Literal[SomeEnum.Foo]]? Or those are not simplified when strict optional isFalse?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Thanks, you're right. I did as suggested and added the corresponding test casetestNoWrongUnreachableWarningWithNoStrictOptionalAndEnumLiteral.

@github-actions
Copy link
Contributor

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

pwndbg (https://github.com/pwndbg/pwndbg)+ pwndbg/aglib/onegadget.py: note: In function "check_constraint":+ pwndbg/aglib/onegadget.py:495: error: Argument 1 to "find" has incompatible type "CheckSatResult"; expected "int | Value | None"  [arg-type]+ pwndbg/aglib/onegadget.py:507: error: Argument 1 to "find" has incompatible type "CheckSatResult"; expected "int | Value | None"  [arg-type]

@ilevkivskyiilevkivskyi merged commit18bfc01 intopython:masterOct 12, 2025
20 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ilevkivskyiilevkivskyiilevkivskyi approved these changes

+1 more reviewer

@sterliakovsterliakovsterliakov approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

False positive: Statement is [unreachable] in loop with iteration-carried flag

3 participants

@tyralla@ilevkivskyi@sterliakov

[8]ページ先頭

©2009-2025 Movatter.jp