Don't use equality to narrow when value is IntEnum/StrEnum (#17866)
IntEnum/StrEnum values compare equal to the corresponding int/str
values, which breaks the logic we use for narrowing based on equality to
a literal value. Special case IntEnum/StrEnum to avoid the incorrect
behavior.
Fix #17860.