qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v6 02/12] qapi: Don't use info as witness of imp


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v6 02/12] qapi: Don't use info as witness of implicit object type
Date: Tue, 06 Oct 2015 10:32:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Eric Blake <address@hidden> writes:

> On 10/02/2015 10:48 AM, Markus Armbruster wrote:
>
>>>> Do it the OO-way: QAPISchemaEntity.is_implicit() returns False.  Any
>>>> subclass that can have implicitly defined instances overrides it:
>>>> QAPISchemaObjectType.is_implicit() tests for ':' prefix,
>>>> QAPISchemaEnumType.is_implicit() tests for 'Kind' suffix (requires
>>>> outlawing it for user enums, if we don't do it already), and so forth.
>>>
>>> But there's still the issue of filtering by subclass.  For the
>>> qapi-types visit_needed() filter, I either write:
>>>
>>> if isinstance(entity, QAPISchemaObjectType) and entity.is_implicit()
>> 
>> If is_implicit() is defined on entities, then this shrinks to just
>> 
>>     entity.is_implicit()
>> 
>> because no non-type entity is implicit.
>
> QAPISchemaEnumType is not a subclass of QAPISchemaObjectType, but it can
> indeed be implicit (currently depends on whether its name ends in
> "Kind").  Right now, the code we generate doesn't care about whether
> enums are implicit. But having enum.is_implicit() return False merely
> because it is not an ObjectType feels wrong; if anything, we'd want to
> name it is_implicit_object() if we are only returning whether an object
> is implicit.

You're right; I got confused.  I think the most straightforward way to
test "is entity an implicitly defined object type" is the way you wrote
it:

    isinstance(entity, QAPISchemaObjectType) and entity.is_implicit()

If we define is_implicit() on entities, either ordering of operands
works.

>>> or what I want to write:
>>>
>>> if entity.is_implicit(QAPISchemaObjectType)
>> 
>> I'm not even sure what that's supposed to mean :)
>
> If entity is an implicit ObjectType, return True. If it is implicit but
> not an object (such as an implicit enum), or is not implicit (regardless
> of whether it is an ObjectType), then return False.
>
> And if you don't need filtering by python type, then
> entity.is_implicit() (shorthand for entity.is_implicit(None)) then gives
> the correct answer whether entity is ObjectType or EnumType or something
> else.

I find

    isinstance(entity, QAPISchemaObjectType) and entity.is_implicit()

more obvious than

    entity.is_implicit(QAPISchemaObjectType)

[...]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]