CompiledTypes: do not let subclasses inherit _internal

Change-Id: I09e04a19d0a550356cf6ed138798af8d1510134a
TN: OA28-063
This commit is contained in:
Pierre-Marie de Rodat
2016-05-17 16:40:48 +02:00
parent 853afbf206
commit b0482b3fe1

View File

@@ -146,8 +146,19 @@ class CompiledTypeMetaclass(type):
def __new__(mcs, name, bases, dct):
cls = type.__new__(mcs, name, bases, dct)
if not dct.get("_internal", False):
# If dct["_internal"] is not defined, mcs.types will include cls but
# cls may inherit an _internal class attribute from its base classes.
# This could yield situations where T._internal is True while T is
# still available in the type repository.
#
# This would be highly confusing for debugging and may trigger bugs if
# code relies on this attribute at some point. In order to prevent
# this, define the attribute no matter what.
dct.setdefault("_internal", False)
if not dct["_internal"]:
mcs.types.append(cls)
return cls