From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi8zo-0003aQ-Iz for qemu-devel@nongnu.org; Fri, 02 Oct 2015 18:40:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi8zk-0005cY-77 for qemu-devel@nongnu.org; Fri, 02 Oct 2015 18:40:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi8zj-0005bX-VB for qemu-devel@nongnu.org; Fri, 02 Oct 2015 18:40:04 -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> <560EB77D.6000704@redhat.com> From: Eric Blake Message-ID: <560F07C2.70300@redhat.com> Date: Fri, 2 Oct 2015 16:40:02 -0600 MIME-Version: 1.0 In-Reply-To: <560EB77D.6000704@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="uGM7dV1DfOfwajwbKpGfcnio7aBxDu1Ri" 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: qemu-devel@nongnu.org, marcandre.lureau@redhat.com, Michael Roth , ehabkost@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --uGM7dV1DfOfwajwbKpGfcnio7aBxDu1Ri Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/02/2015 10:57 AM, Eric Blake wrote: > On 10/02/2015 10:48 AM, Markus Armbruster wrote: >=20 >>>> 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 fort= h. >>> >>> But there's still the issue of filtering by subclass. For the >>> qapi-types visit_needed() filter, I either write: >>> >>> or what I want to write: >>> >>> if entity.is_implicit(QAPISchemaObjectType) >> >> I'm not even sure what that's supposed to mean :) >=20 > 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 (regardles= s > of whether it is an ObjectType), then return False. >=20 > And if you don't need filtering by python type, then > entity.is_implicit() (shorthand for entity.is_implicit(None)) then give= s > the correct answer whether entity is ObjectType or EnumType or somethin= g > else. >=20 >> >>> while still allowing the common case of is_implicit() when I don't ca= re >>> 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. Or, as I just realized, split the public interface from the private interface: class QAPISchemaEntity... def is_implicit(self, typ=3DNone): if typ and not isinstance(self, typ): return False return self._is_implicit() def _is_implicit(self): return not self.info class QAPISchemaObjectTypeMember... def _is_implicit(self): return self.name[0] =3D=3D ':' --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --uGM7dV1DfOfwajwbKpGfcnio7aBxDu1Ri 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/ iQEcBAEBCAAGBQJWDwfCAAoJEKeha0olJ0NqrxQH/2JyEWLKWd5hLjIZcgkx09Py +TNNeszwt6pbtvVFnSR1znDmJCYxpEE+c9Hr3xzUVq+yXDWKeiOI4HwePXDMWkpN mo+CkN70DZbNbGfLduk3KA1lV3oGDM/b/wwDiep4Bn5xk46fbV3BAQVfsBJNFIX+ 95DDS9gP7q0b6thk/58IGXp/7nZBhxD7Er6xxdkQGnWg2LCnfhZ+E6VNqHLP/TDx pJylsMHldgubsJp3C2eLhBlzV9VU+8bspaaaKP1AgI0ZUn06jOgli8bHArdst9qz 82F+u7753b2SDV9pBjVFvq5AEwbrJcqnnH8Xy3MJN2eQCIzy2mPHy9QH5KlkUs8= =qN/x -----END PGP SIGNATURE----- --uGM7dV1DfOfwajwbKpGfcnio7aBxDu1Ri--