Message ID | 20200922210101.4081073-36-jsnow@redhat.com |
---|---|
State | New |
Headers | show |
Series | qapi: static typing conversion, pt1 | expand |
On Tue, Sep 22, 2020 at 05:00:58PM -0400, John Snow wrote: > "John, if pylint told you to jump off a bridge, would you?" > Hey, if it looked like fun, I might. > > Now that this file is clean, enable pylint checks on this file. > > Signed-off-by: John Snow <jsnow@redhat.com> > --- [...] > @@ -148,11 +148,12 @@ def gen_object(name: str, ifcond: List[str], > objects_seen.add(name) > > ret = '' > - if variants: > - for v in variants.variants: > - if isinstance(v.type, QAPISchemaObjectType): > - ret += gen_object(v.type.name, v.type.ifcond, v.type.base, > - v.type.local_members, v.type.variants) > + for variant in variants.variants if variants else (): I'm not sure I like this weird expression, but I believe asking for a 120-patch cleanup series to be respun because of a tiny style issue would be counterproductive, so: Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> > + obj = variant.type > + if not isinstance(obj, QAPISchemaObjectType): > + continue > + ret += gen_object(obj.name, obj.ifcond, obj.base, > + obj.local_members, obj.variants) > > ret += mcgen(''' > > -- > 2.26.2 > -- Eduardo
On 9/23/20 3:14 PM, Eduardo Habkost wrote: > I'm not sure I like this weird expression, but I believe asking > for a 120-patch cleanup series to be respun because of a tiny > style issue would be counterproductive, so: > > Reviewed-by: Eduardo Habkost<ehabkost@redhat.com> I was trying to reduce the indent level to accommodate the longer names, but python ternaries *are* pretty weird. It'd be nice to enforce always having a variants object instead (even if it's empty!) and then add __bool__ and __iter__ methods to QAPISchemaVariants such that you could always do: "if variants" or "for variant in variants" but we're not there just yet... should I just put it back the way it was, with the deep nesting? --js
On Tue, Sep 22, 2020 at 05:00:58PM -0400, John Snow wrote: > "John, if pylint told you to jump off a bridge, would you?" > Hey, if it looked like fun, I might. > :D > Now that this file is clean, enable pylint checks on this file. > > Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com>
On Wed, Sep 23, 2020 at 06:11:01PM -0400, John Snow wrote: > On 9/23/20 3:14 PM, Eduardo Habkost wrote: > > I'm not sure I like this weird expression, but I believe asking > > for a 120-patch cleanup series to be respun because of a tiny > > style issue would be counterproductive, so: > > > > Reviewed-by: Eduardo Habkost<ehabkost@redhat.com> > > I was trying to reduce the indent level to accommodate the longer names, but > python ternaries *are* pretty weird. > > It'd be nice to enforce always having a variants object instead (even if > it's empty!) and then add __bool__ and __iter__ methods to > QAPISchemaVariants such that you could always do: > > "if variants" > > or > > "for variant in variants" > > but we're not there just yet... should I just put it back the way it was, > with the deep nesting? I don't have a strong opinion. I got used to it after seeing the same pattern being used a few times. -- Eduardo
diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index de132d03cf..cebaf600f9 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -7,7 +7,6 @@ ignore-patterns=doc.py, expr.py, parser.py, schema.py, - types.py, visit.py, diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 5533c5a126..78c2a5a3e9 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -49,14 +49,14 @@ def gen_enum_lookup(name: str, .array = (const char *const[]) { ''', c_name=c_name(name)) - for m in members: - ret += gen_if(m.ifcond) - index = c_enum_const(name, m.name, prefix) + for member in members: + ret += gen_if(member.ifcond) + index = c_enum_const(name, member.name, prefix) ret += mcgen(''' [%(index)s] = "%(name)s", ''', - index=index, name=m.name) - ret += gen_endif(m.ifcond) + index=index, name=member.name) + ret += gen_endif(member.ifcond) ret += mcgen(''' }, @@ -79,13 +79,13 @@ def gen_enum(name: str, ''', c_name=c_name(name)) - for m in enum_members: - ret += gen_if(m.ifcond) + for member in enum_members: + ret += gen_if(member.ifcond) ret += mcgen(''' %(c_enum)s, ''', - c_enum=c_enum_const(name, m.name, prefix)) - ret += gen_endif(m.ifcond) + c_enum=c_enum_const(name, member.name, prefix)) + ret += gen_endif(member.ifcond) ret += mcgen(''' } %(c_name)s; @@ -148,11 +148,12 @@ def gen_object(name: str, ifcond: List[str], objects_seen.add(name) ret = '' - if variants: - for v in variants.variants: - if isinstance(v.type, QAPISchemaObjectType): - ret += gen_object(v.type.name, v.type.ifcond, v.type.base, - v.type.local_members, v.type.variants) + for variant in variants.variants if variants else (): + obj = variant.type + if not isinstance(obj, QAPISchemaObjectType): + continue + ret += gen_object(obj.name, obj.ifcond, obj.base, + obj.local_members, obj.variants) ret += mcgen('''
"John, if pylint told you to jump off a bridge, would you?" Hey, if it looked like fun, I might. Now that this file is clean, enable pylint checks on this file. Signed-off-by: John Snow <jsnow@redhat.com> --- scripts/qapi/pylintrc | 1 - scripts/qapi/types.py | 29 +++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-)