at the suggestion of pylint, refactor Factory::isinstance() to be more succinct

This commit is contained in:
Chris Jones 2009-12-09 13:22:27 +00:00
parent a432d10d24
commit 7ed5a573d5
1 changed files with 9 additions and 18 deletions

View File

@ -21,24 +21,15 @@ class Factory(Borg):
def isinstance(self, product, classtype): def isinstance(self, product, classtype):
"""Check if a given product is a particular type of object""" """Check if a given product is a particular type of object"""
if classtype == 'Terminal': types = {'Terminal': 'terminal',
import terminal 'VPaned': 'paned',
return(isinstance(product, terminal.Terminal)) 'HPaned': 'paned',
elif classtype == 'VPaned': 'Paned': 'paned',
import paned 'Notebook': 'notebook',
return(isinstance(product, paned.VPaned)) 'Container': 'container'}
elif classtype == 'HPaned': if classtype in types.keys():
import paned module = __import__(types[classtype], None, None, [''])
return(isinstance(product, paned.HPaned)) return(isinstance(product, getattr(module, classtype)))
elif classtype == 'Paned':
import paned
return(isinstance(product, paned.Paned))
elif classtype == 'Notebook':
import notebook
return(isinstance(product, notebook.Notebook))
elif classtype == 'Container':
import container
return(isinstance(product, container.Container))
else: else:
err('Factory::isinstance: unknown class type: %s' % classtype) err('Factory::isinstance: unknown class type: %s' % classtype)
return(False) return(False)