ContextManagerMagic#
- class penzai.treescope.treescope_ipython.ContextManagerMagic[source]#
Bases:
MagicsMagics class for using
%%withto run a cell under a context manager.Inherited Attributes
configA trait whose value must be an instance of a specified class.
cross_validation_lockA contextmanager for running a block with our cross validation lock set to True.
options_tableparentA trait whose value must be an instance of a specified class.
shellMethods
with_(line, cell)%%withcell magic: runs under a context manager.Attributes
configA trait whose value must be an instance of a specified class.
cross_validation_lockA contextmanager for running a block with our cross validation lock set to True.
magicsoptions_tableparentA trait whose value must be an instance of a specified class.
registeredshellInherited Methods
(expand to view inherited methods)
__init__([shell])add_traits(**traits)Dynamically add trait attributes to the HasTraits instance.
arg_err(func)Print docstring if incorrect arguments were passed
class_config_rst_doc()Generate rST documentation for this class' config options.
class_config_section([classes])Get the config section for this class.
class_get_help([inst])Get the help string for this class in ReST format.
class_get_trait_help(trait[, inst, helptext])Get the helptext string for a single trait.
class_own_trait_events(name)Get a dict of all event handlers defined on this class, not a parent.
class_own_traits(**metadata)Get a dict of all the traitlets defined on this class, not a parent.
class_print_help([inst])Get the help string for a single trait and print it.
class_trait_names(**metadata)Get a list of all the names of this class' traits.
class_traits(**metadata)Get a
dictof all the traits of this class.default_option(fn, optstr)Make an entry in the options_table for fn, with value optstr
format_latex(strng)Format a string for latex inclusion.
has_trait(name)Returns True if the object has a trait with the specified name.
hold_trait_notifications()Context manager for bundling trait change notifications and cross validation.
notify_change(change)Notify observers of a change event
observe(handler[, names, type])Setup a handler to be called when a trait changes.
on_trait_change([handler, name, remove])DEPRECATED: Setup a handler to be called when a trait changes.
parse_options(arg_str, opt_str, *long_opts, **kw)Parse options passed to an argument string.
section_names()return section names as a list
set_trait(name, value)Forcibly sets trait attribute, including read-only attributes.
setup_instance(**kwargs)trait_defaults(*names, **metadata)Return a trait's default value or a dictionary of them
trait_events([name])Get a
dictof all the event handlers of this class.trait_has_value(name)Returns True if the specified trait has a value.
trait_metadata(traitname, key[, default])Get metadata values for trait by key.
trait_names(**metadata)Get a list of all the names of this class' traits.
trait_values(**metadata)A
dictof trait names and their values.traits(**metadata)Get a
dictof all the traits of this class.unobserve(handler[, names, type])Remove a trait change handler.
unobserve_all([name])Remove trait change handlers of any type for the specified name.
update_config(config)Update config and load the new values
- with_(line, cell)[source]#
%%withcell magic: runs under a context manager.The
%%withmagic is syntactic sugar for running a cell under a context manager. It can be used to easily set Penzai’s context variables in a cell without having to explicitly display the final output. In other words,%%with some_var.set_scoped(Foo) result = ... result
expands to something like
with some_var.set_scoped(Foo): result = ... IPython.display.display(result)
- Parameters:
line – Contents of the line where
%%withis. Should be a Python expression for a context manager.cell – Contents of the rest of the cell. Will be run inside the context manager scope.