GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix enum+literal getting coerced to Sequence[str] · python/mypy@1fd8382

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • mypy
    • join.py
  • test-data/unit
    • check-literal.test
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎mypy/join.py‎

Copy file name to clipboardExpand all lines: mypy/join.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ def join_instances(self, t: Instance, s: Instance) -> ProperType:
150150
t, s, subtype_context=SubtypeContext(ignore_type_params=True)
151151
):
152152
result = self.join_instances_via_supertype(t, s)
153+
elif s.type.bases and is_proper_subtype(
154+
s, t, subtype_context=SubtypeContext(ignore_type_params=True)
155+
):
156+
result = self.join_instances_via_supertype(s, t)
157+
elif is_subtype(t, s, subtype_context=SubtypeContext(ignore_type_params=True)):
158+
result = self.join_instances_via_supertype(t, s)
153159
else:
154160
# Now t is not a subtype of s, and t != s. Now s could be a subtype
155161
# of t; alternatively, we need to find a common supertype. This works
Collapse file

‎test-data/unit/check-literal.test‎

Copy file name to clipboardExpand all lines: test-data/unit/check-literal.test
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,3 +3006,20 @@ def check_co(obj: A_co[Literal[1]]) -> None:
30063006
reveal_type(f(obj, '')) # N: Revealed type is "builtins.object"
30073007
reveal_type(g(1, obj)) # N: Revealed type is "builtins.int"
30083008
reveal_type(g('', obj)) # N: Revealed type is "builtins.object"
3009+
3010+
[case testJoinLiteralInstanceAndEnum]
3011+
from typing import Final, TypeVar
3012+
from enum import StrEnum
3013+
3014+
T = TypeVar("T")
3015+
def join(a: T, b: T) -> T: ...
3016+
3017+
class Foo(StrEnum):
3018+
A = "a"
3019+
3020+
CONST: Final = "const"
3021+
3022+
reveal_type(CONST) # N: Revealed type is "Literal['const']?"
3023+
reveal_type(join(Foo.A, CONST)) # N: Revealed type is "builtins.str"
3024+
reveal_type(join(CONST, Foo.A)) # N: Revealed type is "builtins.str"
3025+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.