From b0482b3fe12246fad618b6f736ce6efcd927e110 Mon Sep 17 00:00:00 2001 From: Pierre-Marie de Rodat Date: Tue, 17 May 2016 16:40:48 +0200 Subject: [PATCH] CompiledTypes: do not let subclasses inherit _internal Change-Id: I09e04a19d0a550356cf6ed138798af8d1510134a TN: OA28-063 --- langkit/compiled_types.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/langkit/compiled_types.py b/langkit/compiled_types.py index 0c74619c1..e9e0a028e 100644 --- a/langkit/compiled_types.py +++ b/langkit/compiled_types.py @@ -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