Doubts about brain

Why ipdb session don't show every attribute of a brain with autocomplete?
For example brain.UID exists but it is not listed on ipdb autocomplete.
Is it any black magic on brain code?

Added a stack overflow question

Catalog brains are partly black magic. The list of metadata is stored afaik as attribute record_schema, see NO, you can not except autocompletion to work here...brains are different from what you expect.


brain.schema() does the trick :slight_smile:

ipdb> brain.schema()
['Title', 'exclude_from_nav', 'Type', 'id', 'end', 'Description', 'listCreators', 'is_folderish', 'getId', 'start', 'ExpirationDate', 'Date', 'review_state', 'getRemoteUrl', 'location', 'EffectiveDate', 'portal_type', 'expires', 'ModificationDate', 'getObjSize', 'UID', 'effective', 'Creator', 'getIcon', 'created', 'modified', 'meta_type', 'CreationDate', 'Subject']

All implementations overriding __get_attr__ usally suffer from this. Afaik ipdb looks into the class __dict__ and so it cant find the dynamicly added attributes - they are not part of it. So call it black magic or just flexibility of Python.

Thinking aloud / incomplete wishful thinking: It would be nice if catalog brains, since they involve dynamic class generation ("mybrains" subclassing AbstractCatalogBrain) would define __slots__ for a more standardized way to allow for tools to introspect (assuming tools actually introspect __slots__); of course this is not without time/memory overhead, so maybe only do this when Zope instance is running in debug-mode.


@jensens If you read the zen of python while think on brains you will find that it is really a black magic :smile: