Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,14 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
for p in self.chk.options.untyped_calls_exclude
):
self.msg.untyped_function_call(callee_type, e)

if isinstance(callee_type, Instance) and callee_type.type.has_base("enum.Enum"):
if e.args:
arg_type = get_proper_type(self.accept(e.args[0]))
if (
isinstance(arg_type, LiteralType)
and arg_type.fallback.type == callee_type.type
):
return arg_type
ret_type = self.check_call_expr_with_callee_type(
callee_type, e, fullname, object_type, member
)
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -2492,3 +2492,16 @@ x + T # E: Unsupported left operand type for + ("int")
T() # E: "TypeVar" not callable
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]

[case testEnumIdempotency]
[builtins fixtures/tuple.pyi]
from enum import Enum

class Color(Enum):
RED = 1
BLUE = 2

def f() -> Color:
return Color(Color.RED)

[out]