Skip to content

Invalid return type with sentinel and dict.get #21866

Description

@cdce8p
from typing import assert_type
from typing_extensions import sentinel

Unknown = sentinel("Unknown")

def func(d: dict[str, str]) -> None:
    var = d.get("key", Unknown)
    assert_type(var, str | Unknown)  # <- Error
test.py:8: error: Expression is of type "str | sentinel", not "str | Unknown"  [assert-type]

/CC @JelleZijlstra @edgarrmondragon

Activity

  1. edgarrmondragon commented on Aug 24, 2026

    @edgarrmondragon
    Contributor

    Thanks for the ping and sorry for the delay (I was on holiday last week). Here's a PR: #21888.

  2. added a commit that references this issue on Aug 27, 2026
    44c0d9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions