Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…en strict optional checking is disabled.
This comment has been minimized.
This comment has been minimized.
sterliakov left a comment
There was a problem hiding this 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 commentedOct 11, 2025
Yes, I think you are right. Mypy thought the branch was unreachable because @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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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] |
18bfc01 intopython:masterUh oh!
There was an error while loading.Please reload this page.
Fixes#19849
See#11717 for some background information on
--no-strict-optional.