Uh oh!
There was an error while loading. Please reload this page.
prevent false unreachable warnings for @final instances that occur when strict optional checking is disabled - #20045
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.
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
commented
Oct 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? |
| return UninhabitedType(line=t.line) | ||
| elif isinstance(t, Instance): | ||
| if t.type.is_final or t.type.is_enum: | ||
| if (t.type.is_final or t.type.is_enum) and state.strict_optional: |
There was a problem hiding this comment.
I think this should apply to the branch just below as well. I mean what if in your test you will have x: Optional[Literal[SomeEnum.Foo]]? Or those are not simplified when strict optional is False?
There was a problem hiding this comment.
Thanks, you're right. I did as suggested and added the corresponding test case testNoWrongUnreachableWarningWithNoStrictOptionalAndEnumLiteral.
Diff from mypy_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] |
Uh oh!
There was an error while loading. Please reload this page.
Fixes#19849
See #11717 for some background information on
--no-strict-optional.