Skip to content

Type narrowing not done correctly for bitwise operations with int and instance of subclass of enum.IntFlag #11515

Description

@jonathandung

Describe the bug

When &-ing an int and a member of an enum.IntFlag, another member of the flags is returned, but Pyright reveals it as an int. I believe this isn't an issue with typeshed, since mypy has the correct behaviour.

Code or Screenshots

Code sample in pyright playground

from enum import auto, IntFlag
class Flags(IntFlag):
    A = auto()
    B = auto()
reveal_type(int() & Flags.A)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions