You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mypy infers x.get("a") or x.get("b", "c") to str | None, even when x is dict[str, str] #15534
It does feel like a type context issue, but I think @tmke8 may be right and this is python/typeshed#10293. Unfortunately, as the typeshed PR indicates, that issue may not be easy to fix.
It does feel like a type context issue, but I think @tmke8 may be right and this is python/typeshed#10293. Unfortunately, as the typeshed PR indicates, that issue may not be easy to fix.
(I just merged a different typeshed PR that also hopefully fixes python/typeshed#10293, but had a much less horrifying report from mypy_primer.)
I confirmed that with python/typeshed#10293, the issue is resolved, so no mypy changes will be necessary here. The fix might not make it into mypy v1.5, but it will definitely be included in mypy v1.6 if not.
With mypy v1.4.1:
>mypy -c "x: dict[str, str] = {}; reveal_type(x.get('a') or x.get('b', 'c'))" --custom-typeshed-dir .
<string>:1: note: Revealed type is "builtins.str"
Success: no issues found in 1 source file
With mypy v1.4.1 and --custom-typeshed-dir pointing to an up-to-date clone of typeshed:
>mypy -c "x: dict[str, str] = {}; reveal_type(x.get('a') or x.get('b', 'c'))" --custom-typeshed-dir .
<string>:1: note: Revealed type is "builtins.str"
Success: no issues found in 1 source file
Activity
tmke8 commentedon Jun 27, 2023
Very strange error. If I had to guess, I'd say it has to do with the slightly weird signature of
.get(): python/typeshed#10294You could try defining your own
.get()as in the linked PR and see whether the problem persists.ikonst commentedon Jun 27, 2023
@AlexWaygood
topic-type-context?ikonst commentedon Jun 27, 2023
Ahh, never mind :(
JelleZijlstra commentedon Jun 27, 2023
It does feel like a type context issue, but I think @tmke8 may be right and this is python/typeshed#10293. Unfortunately, as the typeshed PR indicates, that issue may not be easy to fix.
AlexWaygood commentedon Jul 26, 2023
(I just merged a different typeshed PR that also hopefully fixes python/typeshed#10293, but had a much less horrifying report from mypy_primer.)
AlexWaygood commentedon Jul 28, 2023
I confirmed that with python/typeshed#10293, the issue is resolved, so no mypy changes will be necessary here. The fix might not make it into mypy v1.5, but it will definitely be included in mypy v1.6 if not.
With mypy v1.4.1:
With mypy v1.4.1 and
--custom-typeshed-dirpointing to an up-to-date clone of typeshed: