1From 3c642426ea83629c1eedbf5fc877fe51f01ed234 Mon Sep 17 00:00:00 2001
2From: Henri Chataing <[email protected]>
3Date: Thu, 2 Nov 2023 22:10:06 +0000
4Subject: [PATCH] Ensure compatibility with python 3.8
5
6Change-Id: I8db6ec0239fca889b39317c91f75bf0ddc4f3741
7---
8 scripts/pdl/ast.py | 12 +++++++++---
9 1 file changed, 9 insertions(+), 3 deletions(-)
10
11diff --git a/scripts/pdl/ast.py b/scripts/pdl/ast.py
12index 4aff1cc..5ade0fa 100644
13--- a/scripts/pdl/ast.py
14+++ b/scripts/pdl/ast.py
15@@ -66,7 +66,7 @@ class Constraint(Node):
16 @dataclass
17 class Field(Node):
18     parent: Node = field(init=False)
19-    cond: Optional[Constraint] = field(kw_only=True, default=None)
20+    cond: Optional[Constraint] = field(init=False, default=None)
21     # Backlink to the (optional) optional field referencing
22     # this field as condition.
23     cond_for: Optional['Field'] = field(init=False, default=None)
24@@ -277,8 +277,14 @@ def convert_(obj: object) -> object:
25         loc = SourceRange(loc['file'], SourceLocation(**loc['start']), SourceLocation(**loc['end']))
26         constructor = constructors_.get(kind)
27         members = {'loc': loc, 'kind': kind}
28+        cond = None
29         for name, value in obj.items():
30-            if name != 'kind' and name != 'loc':
31+            if name == 'cond':
32+                cond = convert_(value)
33+            elif name != 'kind' and name != 'loc':
34                 members[name] = convert_(value)
35-        return constructor(**members)
36+        val = constructor(**members)
37+        if cond:
38+            val.cond = cond
39+        return val
40     raise Exception('Unhandled json object type')
41--
422.42.0.869.gea05f2083d-goog
43
44