Skip to content

Commit

Permalink
Merge pull request #632 from maxnoe/fix_alias_hierarchy
Browse files Browse the repository at this point in the history
Fix aliases for values deeper in the hierarchy, fixes 631
  • Loading branch information
minrk authored Oct 15, 2020
2 parents a34404b + c1a0591 commit 11e8406
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion traitlets/config/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ def emit_alias_help(self):
longname, fhelp = longname
else:
fhelp = None
classname, traitname = longname.split('.', 1)
classname, traitname = longname.split('.')[-2:]
longname = classname + '.' + traitname
cls = classdict[classname]

trait = cls.class_traits(config=True)[traitname]
Expand Down
29 changes: 29 additions & 0 deletions traitlets/config/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,35 @@ def test_show_config_json(capsys):
assert Config(displayed) == cfg


def test_deep_alias():
from traitlets.config import Application, Configurable
from traitlets import Int

class Foo(Configurable):
val = Int(default_value=5).tag(config=True)

class Bar(Configurable):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.foo = Foo(parent=self)

class TestApp(Application):
name = 'test'

aliases = {'val': 'Bar.Foo.val'}
classes = [Foo, Bar]

def initialize(self, *args, **kwargs):
super().initialize(*args, **kwargs)
self.bar = Bar(parent=self)

app = TestApp()
app.initialize(['--val=10'])
assert app.bar.foo.val == 10
assert len(list(app.emit_alias_help())) > 0


if __name__ == '__main__':
# for test_help_output:
MyApp.launch_instance()

0 comments on commit 11e8406

Please sign in to comment.