From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi1P8-0002N3-UD for qemu-devel@nongnu.org; Fri, 02 Oct 2015 10:33:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi1P5-0000Wi-MB for qemu-devel@nongnu.org; Fri, 02 Oct 2015 10:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50598) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi1P5-0000WR-5W for qemu-devel@nongnu.org; Fri, 02 Oct 2015 10:33:43 -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> From: Eric Blake Message-ID: <560E95C0.5070302@redhat.com> Date: Fri, 2 Oct 2015 08:33:36 -0600 MIME-Version: 1.0 In-Reply-To: <87mvw14ax3.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="lO1UpA14IIE4eTPhmACWcmoHEWK0vWSh7" 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: Michael Roth , marcandre.lureau@redhat.com, qemu-devel@nongnu.org, ehabkost@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --lO1UpA14IIE4eTPhmACWcmoHEWK0vWSh7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/02/2015 08:12 AM, Markus Armbruster wrote: >> Actually, this only works for implicit objects. Implicit enums instea= d >> have self.name[-4:] =3D=3D 'Kind'. But qapi-types cares about implici= t >> objects only. So if I hoist this, I may need something like: >> >> def is_implicit(self, type=3DNone): >> if type and not isinstance(self, type): >> return Fals >> if isinstance(self, QAPISchemaObjectType): >> return self.name[0] =3D=3D ':' >> if isinstance(self, QAPISchemaEnumType): >> return self.name[-4:] =3D=3D 'Kind' >> return False >> >> where qapi-types would call entity.is_implicit(QAPISchemaObjectType). >=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 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() or what I want to write: if entity.is_implicit(QAPISchemaObjectType) while still allowing the common case of is_implicit() when I don't care 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. >> where the indentation is okay. I guess trying to avoid the \ is not >> worth it, if the tools don't complain about it, and that this was a ca= se >> of me prematurely guessing (incorrectly) about what the tools don't li= ke. >=20 > Quoting PEP8: Thanks; that helps. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --lO1UpA14IIE4eTPhmACWcmoHEWK0vWSh7 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/ iQEcBAEBCAAGBQJWDpXAAAoJEKeha0olJ0Nqdn0IAIYqFW2sxj13Nyhbv7u+8d51 lVuaAiR0zEICTIjUSZN1x/SQD0KcDwJoeVmc70Yac2lWwFkk0b0S4oTi2GYHQX9P k9PYR0V3su0WPXE8hKhXoTiPJ6Kt11jswYQ+ZKQYYngues03LTz3nzOqux+SlkS9 d14vsUZ4E9tWOyiZ6j0gtOvoyJCAhdItm2oSwRP0s7H4kvbs0ppuacZvtdIPM00i Gju0cv4pNG3tJ3l/6g+ac6CaphjLahpVauzHxHSkwnEzUkaGxpdii87TR3TJ6T1v h/7kJ5muysW+qZ9Z9YUXyNrFn//CLROzZ6SxVNPRf1g3UOPMrp0tDf6qFvFDyMY= =FUZK -----END PGP SIGNATURE----- --lO1UpA14IIE4eTPhmACWcmoHEWK0vWSh7--