提交 b89111af 编写于 作者: R Radostin Stoyanov 提交者: Daniel P. Berrangé

esx_vi_generator: Simplify get_occurrence_comment

Reduce the number of if-statements and use a single return.
Utilise a dictionary to map between occurrences and values.
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
Signed-off-by: NRadostin Stoyanov <rstoyanov1@gmail.com>
上级 25409b2d
...@@ -75,16 +75,17 @@ class Member: ...@@ -75,16 +75,17 @@ class Member:
def get_occurrence_comment(self): def get_occurrence_comment(self):
if self.occurrence == OCCURRENCE__REQUIRED_ITEM: occurrence_map = {
return "/* required */" OCCURRENCE__REQUIRED_ITEM: "/* required */",
elif self.occurrence == OCCURRENCE__REQUIRED_LIST: OCCURRENCE__REQUIRED_LIST: "/* required, list */",
return "/* required, list */" OCCURRENCE__OPTIONAL_ITEM: "/* optional */",
elif self.occurrence == OCCURRENCE__OPTIONAL_ITEM: OCCURRENCE__OPTIONAL_LIST: "/* optional, list */"
return "/* optional */" }
elif self.occurrence == OCCURRENCE__OPTIONAL_LIST: try:
return "/* optional, list */" return occurrence_map[self.occurrence]
except KeyError:
raise ValueError("unknown occurrence value '%s'" % self.occurrence)
raise ValueError("unknown occurrence value '%s'" % self.occurrence)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册