@@ -2690,41 +2690,191 @@ class A(str, Enum):
26902690 a = "b"
26912691 b = "a"
26922692
2693- A.a == "a"
2694- A.a == "b"
2693+ # Every `if` block in this test should have an error on exactly one of two lines.
2694+ # Either it is reachable (and thus overlapping) or unreachable (and non-overlapping)
26952695
2696- A.a == A.a
2697- A.a == A.b # E: Non-overlapping equality check (left operand type: "Literal[A.a]", right operand type: "Literal[A.b]")
2696+ if A.a == "a": # E: Non-overlapping equality check (left operand type: "Literal[A.a]", right operand type: "Literal['a']")
2697+ 1 + 'a'
2698+ if A.a == "b":
2699+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2700+
2701+ if A.a == 0: # E: Non-overlapping equality check (left operand type: "Literal[A.a]", right operand type: "Literal[0]")
2702+ 1 + 'a'
2703+
2704+ if A.a == A.a:
2705+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2706+ if A.a == A.b: # E: Non-overlapping equality check (left operand type: "Literal[A.a]", right operand type: "Literal[A.b]")
2707+ 1 + 'a'
26982708
26992709class B(StrEnum):
27002710 a = "b"
27012711 b = "a"
27022712
2703- B.a == "a"
2704- B.a == "b"
2713+ if B.a == "a": # E: Non-overlapping equality check (left operand type: "Literal[B.a]", right operand type: "Literal['a']")
2714+ 1 + 'a'
2715+ if B.a == "b":
2716+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
27052717
2706- B.a == B.a
2707- B.a == B.b # E: Non-overlapping equality check (left operand type: "Literal[B.a]", right operand type: "Literal[B.b]")
2718+ if B.a == 0: # E: Non-overlapping equality check (left operand type: "Literal[ B.a]", right operand type: "Literal[0]")
2719+ 1 + 'a'
27082720
2709- B.a == A.a # E: Non-overlapping equality check (left operand type: "Literal[B.a]", right operand type: "Literal[A.a]")
2721+ if B.a == B.a:
2722+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2723+ if B.a == B.b: # E: Non-overlapping equality check (left operand type: "Literal[B.a]", right operand type: "Literal[B.b]")
2724+ 1 + 'a'
2725+
2726+ if B.a == A.a: # E: Non-overlapping equality check (left operand type: "Literal[B.a]", right operand type: "Literal[A.a]")
2727+ 1 + 'a'
27102728
27112729class C(IntEnum):
27122730 a = 0
2731+ b = 1
2732+
2733+ if C.a == "a": # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal['a']")
2734+ 1 + 'a'
2735+ if C.a == "b": # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal['b']")
2736+ 1 + 'a'
27132737
2714- C.a == "a" # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal['a']")
2715- C.a == "b" # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal['b']")
2738+ if C.a == 0:
2739+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2740+ if C.a == 1: # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal[1]")
2741+ 1 + 'a'
27162742
2717- C.a == C.a
2718- C.a == C.b
2743+ if C.a == C.a:
2744+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2745+ if C.a == C.b: # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal[C.b]")
2746+ 1 + 'a'
27192747
27202748class D(int, Enum):
27212749 a = 0
2750+ b = 1
2751+
2752+ if D.a == "a": # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal['a']")
2753+ 1 + 'a'
2754+ if D.a == "b": # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal['b']")
2755+ 1 + 'a'
2756+
2757+ if D.a == 0:
2758+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2759+ if D.a == 1: # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal[1]")
2760+ 1 + 'a'
2761+
2762+ if D.a == D.a:
2763+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2764+ if D.a == D.b: # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal[D.b]")
2765+ 1 + 'a'
27222766
2723- D.a == "a" # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal['a']")
2724- D.a == "b" # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal['b']")
2767+ if D.a == C.a: # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal[C.a]")
2768+ 1 + 'a'
2769+ [builtins fixtures/dict.pyi]
2770+
2771+
2772+ [case testEnumItemsEqualityToLiteralsInStub]
2773+ # flags: --python-version=3.11 --strict-equality
2774+ from mystub import A, B, C, D
2775+
2776+ # Every `if` block in this test should have an error on exactly one of two lines.
2777+ # Either it is reachable (and thus overlapping) or unreachable (and non-overlapping)
2778+
2779+ if A.a == "a":
2780+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2781+ if A.a == "b":
2782+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2783+
2784+ if A.a == 0: # E: Non-overlapping equality check (left operand type: "Literal[A.a]", right operand type: "Literal[0]")
2785+ 1 + 'a'
2786+
2787+ if A.a == A.a:
2788+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2789+ if A.a == A.b: # E: Non-overlapping equality check (left operand type: "Literal[A.a]", right operand type: "Literal[A.b]")
2790+ 1 + 'a'
2791+
2792+ if B.a == "a":
2793+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2794+ if B.a == "b":
2795+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2796+
2797+ if B.a == 0: # E: Non-overlapping equality check (left operand type: "Literal[B.a]", right operand type: "Literal[0]")
2798+ 1 + 'a'
2799+
2800+ if B.a == B.a:
2801+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2802+ if B.a == B.b: # E: Non-overlapping equality check (left operand type: "Literal[B.a]", right operand type: "Literal[B.b]")
2803+ 1 + 'a'
2804+
2805+ if B.a == A.a: # E: Non-overlapping equality check (left operand type: "Literal[B.a]", right operand type: "Literal[A.a]")
2806+ 1 + 'a'
2807+
2808+ if C.a == "a": # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal['a']")
2809+ 1 + 'a'
2810+ if C.a == "b": # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal['b']")
2811+ 1 + 'a'
2812+
2813+ if C.a == 0:
2814+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2815+ if C.a == 1:
2816+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2817+
2818+ if C.a == C.a:
2819+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2820+ if C.a == C.b: # E: Non-overlapping equality check (left operand type: "Literal[C.a]", right operand type: "Literal[C.b]")
2821+ 1 + 'a'
2822+
2823+ if D.a == "a": # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal['a']")
2824+ 1 + 'a'
2825+ if D.a == "b": # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal['b']")
2826+ 1 + 'a'
2827+
2828+ if D.a == 0:
2829+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2830+ if D.a == 1:
2831+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2832+
2833+ if D.a == D.a:
2834+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2835+ if D.a == D.b: # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal[D.b]")
2836+ 1 + 'a'
2837+
2838+ if D.a == C.a: # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal[C.a]")
2839+ 1 + 'a'
2840+
2841+ [file mystub.pyi]
2842+ from enum import Enum, StrEnum, IntEnum
2843+
2844+ class A(str, Enum):
2845+ a = ...
2846+ b = ...
27252847
2726- D.a == D.a
2727- D.a == D.b
2848+ class B(StrEnum):
2849+ a = ...
2850+ b = ...
2851+
2852+ class C(int, Enum):
2853+ a = ...
2854+ b = ...
2855+
2856+ class D(IntEnum):
2857+ a = ...
2858+ b = ...
2859+ [builtins fixtures/dict.pyi]
2860+
2861+
2862+ [case testEnumItemsEqualityToLiteralsWithAlias-xfail]
2863+ # flags: --python-version=3.11 --strict-equality
2864+ # TODO: mypy does not support enum member aliases now.
2865+ from enum import Enum, IntEnum
2866+
2867+ class A(str, Enum):
2868+ a = "c"
2869+ b = a
2870+
2871+ if A.a == A.b:
2872+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
2873+
2874+ class B(IntEnum):
2875+ a = 0
2876+ b = a
27282877
2729- D.a == C.a # E: Non-overlapping equality check (left operand type: "Literal[D.a]", right operand type: "Literal[C.a]")
2878+ if B.a == B.b:
2879+ 1 + 'a' # E: Unsupported operand types for + ("int" and "str")
27302880[builtins fixtures/dict.pyi]
0 commit comments