commit ca99f03151ecfa67a27591a0097dae9a890a6d75 Author: Gregory M. Turner Date: Wed Dec 3 00:26:12 2014 -0800 types.py: correctly ignore virtual types During new_class and prepare_class, don't allow __instancecheck__ and __subclasscheck__ of putative metaclasses to influence the selection of the actual metaclass that is used, as not only is this behavior inconsistent with that of __build_class__, but with type_new. Signed-off-by: Gregory M. Turner diff --git a/Lib/types.py b/Lib/types.py index 7e4fec2..3022428 100644 --- a/Lib/types.py +++ b/Lib/types.py @@ -73,7 +73,7 @@ def prepare_class(name, bases=(), kwds=None): meta = type(bases[0]) else: meta = type - if isinstance(meta, type): + if type.__instancecheck__(type, meta): # when meta is a type, we first determine the most-derived metaclass # instead of invoking the initial candidate directly meta = _calculate_meta(meta, bases) @@ -88,9 +88,9 @@ def _calculate_meta(meta, bases): winner = meta for base in bases: base_meta = type(base) - if issubclass(winner, base_meta): + if type.__subclasscheck__(base_meta, winner): continue - if issubclass(base_meta, winner): + if type.__subclasscheck__(winner, base_meta): winner = base_meta continue # else: