Received: from eggs.gnu.org ([2001:4830:134:3::10]:37096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjNg3-0003JA-QN for qemu-devel@nongnu.org; Tue, 06 Oct 2015 04:32:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZjNg0-0003Zw-L4 for qemu-devel@nongnu.org; Tue, 06 Oct 2015 04:32:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60351) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjNg0-0003Yd-6g for qemu-devel@nongnu.org; Tue, 06 Oct 2015 04:32:48 -0400 From: Markus Armbruster References: <1443760312-656-1-git-send-email-eblake@redhat.com> <1443760312-656-3-git-send-email-eblake@redhat.com> <87eghdhhxy.fsf@blackfin.pond.sub.org> <560E7E74.5090600@redhat.com> <87mvw14ax3.fsf@blackfin.pond.sub.org> <560E95C0.5070302@redhat.com> <87a8s1p673.fsf@blackfin.pond.sub.org> <560EB77D.6000704@redhat.com> Date: Tue, 06 Oct 2015 10:32:44 +0200 In-Reply-To: <560EB77D.6000704@redhat.com> (Eric Blake's message of "Fri, 2 Oct 2015 10:57:33 -0600") Message-ID: <87si5os8gj.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v6 02/12] qapi: Don't use info as witness of implicit object type List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, marcandre.lureau@redhat.com, Michael Roth , ehabkost@redhat.com Eric Blake 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) [...]