diff --git a/mypy/semanal.py b/mypy/semanal.py index 973a28db0588..2bd09597f63f 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -221,7 +221,7 @@ infer_reachability_of_match_statement, ) from mypy.scope import Scope -from mypy.semanal_enum import EnumCallAnalyzer +from mypy.semanal_enum import ENUM_BASES, EnumCallAnalyzer from mypy.semanal_namedtuple import NamedTupleAnalyzer from mypy.semanal_newtype import NewTypeAnalyzer from mypy.semanal_shared import ( @@ -5986,6 +5986,13 @@ def visit_call_expr(self, expr: CallExpr) -> None: expr.analyzed.line = expr.line expr.analyzed.column = expr.column expr.analyzed.accept(self) + elif refers_to_fullname(expr.callee, ENUM_BASES): + assert isinstance(expr.callee, RefExpr) + for a in expr.args: + a.accept(self) + + # ensure we get analytics about enum.Enum, even if we don't assign it + self.enum_call_analyzer.parse_enum_call_args(expr, expr.callee.fullname.split(".")[-1]) else: # Normal call expression. calculate_type_forms = TYPE_FORM in self.options.enable_incomplete_feature diff --git a/mypy/semanal_enum.py b/mypy/semanal_enum.py index b1e267b4c781..cb77f56a6ba4 100644 --- a/mypy/semanal_enum.py +++ b/mypy/semanal_enum.py @@ -35,9 +35,7 @@ # Note: 'enum.EnumMeta' is deliberately excluded from this list. Classes that directly use # enum.EnumMeta do not necessarily automatically have the 'name' and 'value' attributes. -ENUM_BASES: Final = frozenset( - ("enum.Enum", "enum.IntEnum", "enum.Flag", "enum.IntFlag", "enum.StrEnum") -) +ENUM_BASES: Final = ("enum.Enum", "enum.IntEnum", "enum.Flag", "enum.IntFlag", "enum.StrEnum") ENUM_SPECIAL_PROPS: Final = frozenset( ( "name", diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index 3bcf9745a801..ec8011254509 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -2681,3 +2681,9 @@ reveal_type(Wrapper.Nested.FOO) # N: Revealed type is "Literal[__main__.Wrapper reveal_type(Wrapper.Nested.FOO.value) # N: Revealed type is "builtins.ellipsis" reveal_type(Wrapper.Nested.FOO._value_) # N: Revealed type is "builtins.ellipsis" [builtins fixtures/enum.pyi] + +[case testCatchesEnumCallWithoutAssignment] +import enum + +enum.Enum() # E: Too few arguments for Enum() +[builtins fixtures/tuple.pyi]