Skip to content

Commit e469a85

Browse files
committed
fix slots calculation
1 parent 48f53a3 commit e469a85

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

mypy/checkmember.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,13 +1484,7 @@ def analyze_decorator_or_funcbase_access(
14841484
if isinstance(defn, Decorator):
14851485
return analyze_var(name, defn.var, itype, mx)
14861486
typ = function_type(defn, mx.chk.named_type("builtins.function"))
1487-
is_trivial_self = False
1488-
if isinstance(defn, Decorator):
1489-
# Use fast path if there are trivial decorators like @classmethod or @property
1490-
is_trivial_self = defn.func.is_trivial_self and not defn.decorators
1491-
elif isinstance(defn, (FuncDef, OverloadedFuncDef)):
1492-
is_trivial_self = defn.is_trivial_self
1493-
if is_trivial_self:
1487+
if isinstance(defn, (FuncDef, OverloadedFuncDef)) and defn.is_trivial_self:
14941488
return bind_self_fast(typ, mx.self_type)
14951489
typ = check_self_arg(typ, mx.self_type, defn.is_class, mx.context, name, mx.msg)
14961490
return bind_self(typ, original_type=mx.self_type, is_classmethod=defn.is_class)

mypy/typeops.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,19 @@ def named_type(fullname: str) -> Instance:
12571257

12581258
def _is_disjoint_base(info: TypeInfo) -> bool:
12591259
# It either has the @disjoint_base decorator or defines nonempty __slots__.
1260-
return info.is_disjoint_base or bool(info.slots)
1260+
if info.is_disjoint_base:
1261+
return True
1262+
if not info.slots:
1263+
return False
1264+
own_slots = {
1265+
slot
1266+
for slot in info.slots
1267+
if not any(
1268+
base_info.type.slots is not None and slot in base_info.type.slots
1269+
for base_info in info.bases
1270+
)
1271+
}
1272+
return bool(own_slots)
12611273

12621274

12631275
def _get_disjoint_base_of(instance: Instance) -> TypeInfo | None:

0 commit comments

Comments
 (0)