From c027d1349e73da499c85b51177e0fdcc524300e3 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 7 Mar 2023 15:50:36 +0100 Subject: [PATCH] Python: use `self` as default `_root` only in top-level types ... as in Java, see https://github.com/kaitai-io/kaitai_struct_compiler/blob/829a14f1e33e8e48eeae726c8a287a5967bcb668/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala#L153 This commit was extracted from the `serialization` branch (originally e776c982f8ba5b039bdcacd1db48ecbe77588df6), see https://github.com/kaitai-io/kaitai_struct_compiler/pull/255 --- .../scala/io/kaitai/struct/languages/PythonCompiler.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala index f119405ca..992e4ee98 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala @@ -101,7 +101,11 @@ class PythonCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.inc out.puts("self._io = _io") out.puts("self._parent = _parent") - out.puts("self._root = _root if _root else self") + if (name == rootClassName) { + out.puts("self._root = _root if _root else self") + } else { + out.puts("self._root = _root") + } if (isHybrid) out.puts("self._is_le = _is_le")