On 10/02/2015 08:12 AM, Markus Armbruster wrote: >> Actually, this only works for implicit objects. Implicit enums instead >> have self.name[-4:] == 'Kind'. But qapi-types cares about implicit >> objects only. So if I hoist this, I may need something like: >> >> def is_implicit(self, type=None): >> if type and not isinstance(self, type): >> return Fals >> if isinstance(self, QAPISchemaObjectType): >> return self.name[0] == ':' >> if isinstance(self, QAPISchemaEnumType): >> return self.name[-4:] == 'Kind' >> return False >> >> where qapi-types would call entity.is_implicit(QAPISchemaObjectType). > > 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=None):
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 case
>> of me prematurely guessing (incorrectly) about what the tools don't like.
>
> Quoting PEP8:
Thanks; that helps.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
