From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi3eS-0003i4-Nb for qemu-devel@nongnu.org; Fri, 02 Oct 2015 12:57:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi3eO-000249-Mu for qemu-devel@nongnu.org; Fri, 02 Oct 2015 12:57:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi3eO-000243-FV for qemu-devel@nongnu.org; Fri, 02 Oct 2015 12:57:40 -0400 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> From: Eric Blake Message-ID: <560EB77D.6000704@redhat.com> Date: Fri, 2 Oct 2015 10:57:33 -0600 MIME-Version: 1.0 In-Reply-To: <87a8s1p673.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="swXi6tpdQ1DCiLPtdxmknrstqr9QBuEsg" 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: Markus Armbruster Cc: marcandre.lureau@redhat.com, Michael Roth , ehabkost@redhat.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --swXi6tpdQ1DCiLPtdxmknrstqr9QBuEsg Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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= =2E >> >> 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() >=20 > If is_implicit() is defined on entities, then this shrinks to just >=20 > entity.is_implicit() >=20 > 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. >=20 >> or what I want to write: >> >> if entity.is_implicit(QAPISchemaObjectType) >=20 > 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. >=20 >> while still allowing the common case of is_implicit() when I don't car= e >> which type is doing the testing. Since python doesn't allow method >> overloads, I'd have to repeat the: >> >> def is_implicit(self, type=3DNone): >> if type and not isinstance(self, type): >> return False >> >> prefix in each subclass that overrides the basic version. >=20 > AH, you seem to propose to define E.is_implicit(T) as "E is implicitly > defined and not an instance of T". Why not simply keep the two > predicates seperate? Am I missing something? No, I was thinking E.is_implicit(T) is "E is implicitly defined and IS an instance of T", while E.is_implicit(None) (the default) doesn't care about type relations. To get that semantic, each override of the base class .is_implicit() has to first filter out all non-T, before going into its class-specific tests (ObjectType for leading ':', EnumType for trailing 'Kind'). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --swXi6tpdQ1DCiLPtdxmknrstqr9QBuEsg Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWDrd9AAoJEKeha0olJ0NqNxkH/iAnrQCkNstCAacI/k0bAqJn tSJ68jTr6jVrTUu9GQiq8hBZTriRKdT5DPuupW245vx60nfhGeFrh+q2hoF+0EGd 0nvBBnEykK+3R+I3eqZiRBxM0mvEU5OMOT5IkbYFVdPRHmy/r1JqpgwgGDkmJyv7 +nEAzt4SAQFc4TzWWI3oxAzQoYwzD6a9IjnMMC/vXcjsxnHIN4uYtAYMnf7mMaK0 YV4NXX1i+I8wnNqidA62f7Puf/Bfl/jLoU6xlgeUUKhbFvggAYThmv2WsUVFmPfC LUtQVipujNzvMWRXx5ST+D4MQcOueTPQ77O8qmmGe4eOOFAyUB7YRv5SRHyxP7M= =akU7 -----END PGP SIGNATURE----- --swXi6tpdQ1DCiLPtdxmknrstqr9QBuEsg--