Skip to content

Support narrowing generic upper bounds #653

@thejchap

Description

@thejchap

Summary

No error should be emitted on this snippet:

class A:
    pass

class B:
    x: int = 0

def _[C: A | B](c: C):
    if isinstance(c, B):
        reveal_type(c)
        c.x = 42

More discussion here: astral-sh/ruff#18527 (comment)

Example: https://play.ty.dev/62d91bdb-cbf1-4758-8f2c-6a26722c9f47

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggenericsBugs or features relating to ty's generics implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions