traits.trait_factory Module

Defines the TraitFactory class and related objects.

A TraitFactory is a class which allows deferred, but cached, creation of CTrait instances. The TraitFactory API provides the as_ctrait method so that the trait conversion functions can generate CTrait instances in a standard way.


class traits.trait_factory.TraitFactory(maker_function=None)[source]

A factory class that allows deferred creation of traits

Traits created by TraitFactory instances are cached, and the cached trait is returned by all subsequent calls to the same TraitFactory instance.


Get the CTrait instance from the factory.

class traits.trait_factory.TraitImportError(message)[source]

TraitFactory subclass that always fails when creating a CTrait

This class is designed for uses such as deferring import problems until encountering code that actually tries to use the unimportable trait.



Returns a trait created from a TraitFactory instance