#4590·ty

`Container[Flag] | Flag` does not accept Flag

Author: zzjjbbCreated Sep 24, 2026Updated Sep 30, 2026
Labelsbuggenericsprotocolsenumsregression

Summary

This code can pass ty check for version 0.0.53 but not for 0.0.54 or higher, including 0.0.84.

Code ty.py

python3
from collections.abc import Container
from enum import Flag, auto


class MyFlag(Flag):
    a = auto()

def f(x: MyFlag | Container[MyFlag]) -> bool:
    return MyFlag.a in x

f(MyFlag.a)

Checking

ty check ty.py
error[invalid-argument-type]: Argument to function `f` is incorrect
  --> ty.py:11:3
   |
11 | f(MyFlag.a)
   |   ^^^^^^^^ Expected `Container[MyFlag]`, found `Literal[MyFlag.a]`
info: type `Literal[MyFlag.a]` is not assignable to protocol `Container[MyFlag]`
info: └── protocol member `__contains__` is incompatible
info:     └── parameter `x` has an incompatible type: `MyFlag` is not assignable to `Literal[MyFlag.a]`
info: Function defined here
 --> ty.py:8:5
  |
8 | def f(x: MyFlag | Container[MyFlag]) -> bool:
  |     ^ ----------------------------- Parameter declared here

Found 1 diagnostic

This error is obviously unexpected. Still, I'd like to know what the best signature should be for the function f in code above. Thanks!

Version

ty 0.0.84