Skip to content

Commit 989c9f3

Browse files
committed
Fix: Add exception handling and resolve issues caused by AnyType
1 parent f6c8dfd commit 989c9f3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

mypy/plugins/attrs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,18 +1032,15 @@ def _get_attrs_init_type(typ: Instance) -> CallableType | None:
10321032
init_method = typ.type.get_method("__init__") or typ.type.get_method(ATTRS_INIT_NAME)
10331033
if init_method is None:
10341034
return None
1035-
1035+
10361036
# case 1: normal FuncDef
10371037
if isinstance(init_method, FuncDef) and isinstance(init_method.type, CallableType):
10381038
return init_method.type
10391039

10401040
# case 2: overloaded method
10411041
if isinstance(init_method, OverloadedFuncDef) and isinstance(init_method.type, Overloaded):
1042-
# use the first overload item as a representative
1043-
first = init_method.type.items[0]
1044-
if isinstance(first, CallableType):
1045-
return first
1046-
1042+
if len(init_method.type.items) >= 1:
1043+
return AnyType(TypeOfAny.explicit)
10471044
return None
10481045

10491046

@@ -1098,6 +1095,9 @@ def _get_expanded_attr_types(
10981095
if init_func is None:
10991096
_fail_not_attrs_class(ctx, display_typ, parent_typ)
11001097
return None
1098+
if isinstance(init_func, AnyType):
1099+
_fail_not_attrs_class(ctx, display_typ, parent_typ)
1100+
return None
11011101
init_func = expand_type_by_instance(init_func, typ)
11021102
# [1:] to skip the self argument of AttrClass.__init__
11031103
field_names = cast(list[str], init_func.arg_names[1:])

0 commit comments

Comments
 (0)