Utils#

A simple utility to import something by its string name.

traitlets.import_item(name: str) Any#

Import and return bar given the string foo.bar.

Calling bar = import_item("foo.bar") is the functional equivalent of executing the code from foo import bar.

Parameters:

name (string) – The fully qualified name of the module/package being imported.

Returns:

mod – The module that was imported.

Return type:

module object

traitlets.signature_has_traits(cls: Type[T]) Type[T]#

Return a decorated class with a constructor signature that contain Trait names as kwargs.

This is a way to expand the signature of the HasTraits class constructor. This enables auto-completion of trait-names in IPython and xeus-python when having Jedi>=0.15 by adding trait names with their default values in the constructor signature.

Example:

from inspect import signature

from traitlets import HasTraits, Int, Unicode, signature_has_traits

@signature_has_traits
class Foo(HasTraits):
    number1 = Int()
    number2 = Int()
    value = Unicode('Hello')

    def __init__(self, arg1, **kwargs):
        self.arg1 = arg1

        super(Foo, self).__init__(**kwargs)

print(signature(Foo))  # <Signature (arg1, *, number1=0, number2=0, value='Hello', **kwargs)>