@@ -506,28 +506,57 @@ def _is_disjoint_base(typ: type[object]) -> bool:
506506def _verify_disjoint_base (
507507 stub : nodes .TypeInfo , runtime : type [object ], object_path : list [str ]
508508) -> Iterator [Error ]:
509- # If it's final, doesn't matter whether it's a disjoint base or not
510- if stub .is_final :
511- return
512509 is_disjoint_runtime = _is_disjoint_base (runtime )
513510 # Don't complain about missing @disjoint_base if there are __slots__, because
514511 # in that case we can infer that it's a disjoint base.
515- if is_disjoint_runtime and not stub .is_disjoint_base and not runtime .__dict__ .get ("__slots__" ):
512+ if (
513+ is_disjoint_runtime
514+ and not stub .is_disjoint_base
515+ and not runtime .__dict__ .get ("__slots__" )
516+ and not stub .is_final
517+ and not (stub .is_enum and stub .enum_members )
518+ ):
516519 yield Error (
517520 object_path ,
518521 "is a disjoint base at runtime, but isn't marked with @disjoint_base in the stub" ,
519522 stub ,
520523 runtime ,
521524 stub_desc = repr (stub ),
522525 )
523- elif not is_disjoint_runtime and stub .is_disjoint_base :
524- yield Error (
525- object_path ,
526- "is marked with @disjoint_base in the stub, but isn't a disjoint base at runtime" ,
527- stub ,
528- runtime ,
529- stub_desc = repr (stub ),
530- )
526+ elif stub .is_disjoint_base :
527+ if not is_disjoint_runtime :
528+ yield Error (
529+ object_path ,
530+ "is marked with @disjoint_base in the stub, but isn't a disjoint base at runtime" ,
531+ stub ,
532+ runtime ,
533+ stub_desc = repr (stub ),
534+ )
535+ if runtime .__dict__ .get ("__slots__" ):
536+ yield Error (
537+ object_path ,
538+ "is marked as @disjoint_base, but also has slots; add __slots__ instead" ,
539+ stub ,
540+ runtime ,
541+ stub_desc = repr (stub ),
542+ )
543+ elif stub .is_final :
544+ yield Error (
545+ object_path ,
546+ "is marked as @disjoint_base, but also marked as @final; remove @disjoint_base" ,
547+ stub ,
548+ runtime ,
549+ stub_desc = repr (stub ),
550+ )
551+ elif stub .is_enum and stub .enum_members :
552+ yield Error (
553+ object_path ,
554+ "is marked as @disjoint_base, but is an enum with members, which is implicitly final; "
555+ "remove @disjoint_base" ,
556+ stub ,
557+ runtime ,
558+ stub_desc = repr (stub ),
559+ )
531560
532561
533562def _verify_metaclass (
0 commit comments