Skip to content

Commit 91ce63a

Browse files
committed
[FIX] tools/generate-inherit.py: handle Odoo 17
Part-of: odoo/upgrade#5330
1 parent e52c040 commit 91ce63a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tools/generate-inherit.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ def parse(cls, name):
102102
name = name.split(".", 1)[-1]
103103
return cls(name)
104104

105+
@property
106+
def python_target(self):
107+
bounds = [
108+
[(7, 0), black.mode.TargetVersion.PY27],
109+
[(10, 17), black.mode.TargetVersion.PY36],
110+
[(15, 0), black.mode.TargetVersion.PY37],
111+
[(16, 3), black.mode.TargetVersion.PY310],
112+
]
113+
for bound, target in reversed(bounds):
114+
if bound <= self.ints:
115+
return target
116+
raise RuntimeError(f"Cannot determine python target for {self.name}")
117+
105118

106119
@dataclass(order=True)
107120
class Inherit:
@@ -116,7 +129,7 @@ def apply_on(self, version: Version) -> bool:
116129
return self.born <= version < self.dead
117130

118131

119-
_NEXT_MAJOR = 17
132+
_NEXT_MAJOR = 18
120133
_VERSIONS = {Version(f"{major}.0") for major in range(7, _NEXT_MAJOR)}
121134
_VERSIONS |= {Version(f"saas-{saas}") for saas in range(1, 19)}
122135
_VERSIONS |= {Version(f"saas-{major}.{minor}") for major in range(11, _NEXT_MAJOR) for minor in range(1, 6)}
@@ -396,7 +409,7 @@ def main(options: Namespace):
396409
if fname in IGNORED_FILES or "test" in fname:
397410
continue
398411
code, _ = _read_python_source(pyfile)
399-
node = black.lib2to3_parse(code)
412+
node = black.lib2to3_parse(code, [version.python_target])
400413
try:
401414
list(visitor.visit(node))
402415
except Exception:

0 commit comments

Comments
 (0)