def default_text_editor(trait, type=None):
    """ Return a default text editor for a trait.

    Parameters
    ----------
    trait : TraitType
        The trait we are constructing the editor for.
    type : callable, optional
        A callable (usually a Python type) to use to evaluate the text content
        of the editor and return the correct type of value for the trait.

    Returns
    -------
    TextEditor
        A TraitsUI TextEditor instance for the trait.
    """
    auto_set = trait.auto_set
    if auto_set is None:
        auto_set = True
    enter_set = trait.enter_set or False
    from traitsui.api import TextEditor
    if type is None:
        return TextEditor(auto_set=auto_set, enter_set=enter_set)
    return TextEditor(auto_set=auto_set, enter_set=enter_set, evaluate=type)
