Skip to content

PEP 661 sentinel support #3589

Description

@inducer

Describe the Bug

When running pyrefly on this snippet:

from __future__ import annotations

from typing import TypeAlias

from typing_extensions import Sentinel


AUTO = Sentinel("AUTO")


ToLoopyTypeConvertible: TypeAlias = AUTO

configured with preset = "strict", I get the following error:

ERROR Expected `ToLoopyTypeConvertible` to be a type alias, got `Sentinel` [invalid-type-alias]
  --> sent.py:11:37
   |
11 | ToLoopyTypeConvertible: TypeAlias = AUTO
   |                                     ^^^^
   |
 INFO 1 error

basedpyright (and pyright configured with experimental features) accepts this code.

This is with pyrefly 1.0.0. The sandbox link reproduces the issue for me.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEA%2Bg2AK4AuLlMTdENxuSmzoZ0uNqjYRc6OAB10CsNXptSxCOgDmvfoOEAVdTACCUCKnmL0y2nTUbtDGPjYxZ02boFC6AZXcpdBgoBTD0EwBVAwB5OgBef0DNEIAKORAo2IyASnCFA1wAGVxcMiNiGABhGQA3GCEIbFhEOgrTc0sEuiyYhRAAGhAyLjAoUkI2WigKYi44GGFEjLg2SggAYzYMkABfIdQtiHqAMWgYCjQsPCIyPaA

(Only applicable for extension issues) IDE Information

No response

Activity

  1. yangdanny97 commented on May 27, 2026

    @yangdanny97
    Collaborator

    Thanks for reporting. I'm not clear on the status of sentinel support in Pyrefly ATM, so would need to look into that as a first step

  2. changed the title [-]Type aliases of PEP661 sentinels say "Expected ... to be a type alias"[/-] [+]PEP 661 sentinel support[/+] on May 27, 2026
  3. yangdanny97 commented on May 27, 2026

    @yangdanny97
    Collaborator

    I'm pretty sure we just don't support it yet because it was just accepted

  4. hrolfurgylfa commented on Jun 13, 2026

    @hrolfurgylfa
    Contributor

    This is now solved on the latest main branch with the merging of #3575

    The only edge-case I could see with the testing of this snippet is that you have to use the sentinel itself, AUTO, in narrowing operations like is AUTO/is not AUTO, you can't use the type alias. So something like this doesn't work:

    from typing import TypeAlias
    from typing_extensions import Sentinel
    
    AUTO = Sentinel("AUTO")
    ToLoopyTypeConvertible: TypeAlias = AUTO
    
    def foo(a: int | ToLoopyTypeConvertible) -> None:
        if a is ToLoopyTypeConvertible:
            reveal_type(a)

    But I'm not sure if you are supposed to be able to use the type alias for narrowing, I don't think PEP 661 mentioned anything regarding that, so this is probably fine. If not I can take a look at adding support for that as well.

  5. rchen152 commented on Jun 13, 2026

    @rchen152
    Contributor

    Yeah, I think we can close this issue now. I checked, and pyright allows ToLoopyTypeConvertible to be used in place of AUTO in the type annotation but not for narrowing, so pyrefly's behavior matches pyright there.

    Sentinel support will be available in pyrefly version 1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions