Skip to content
Open
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/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions mypy/semanal_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]