class_docstr: A singleton application with full configuration support.
class_docstr_tok: ["A","singleton","application","with","full","configuration","support","."]
docstr: flatten flags and aliases, so cl-args override as expected.
  
  This prevents issues such as an alias pointing to InteractiveShell,
  but a config file setting the same trait in TerminalInteraciveShell
  getting inappropriate priority over the command-line arg.
  
  Only aliases with exactly one descendent in the class list
  will be promoted.
code: def flatten_flags(self):
      """flatten flags and aliases, so cl-args override as expected.
  
      This prevents issues such as an alias pointing to InteractiveShell,
      but a config file setting the same trait in TerminalInteraciveShell
      getting inappropriate priority over the command-line arg.
  
      Only aliases with exactly one descendent in the class list
      will be promoted.
  
      """
      # build a tree of classes in our list that inherit from a particular
      # it will be a dict by parent classname of classes in our list
      # that are descendents
      mro_tree = defaultdict(list)
      for cls in self.classes:
          clsname = cls.__name__
          for parent in cls.mro()[1:-3]:
              # exclude cls itself and Configurable,HasTraits,object
              mro_tree[parent.__name__].append(clsname)
      # flatten aliases, which have the form:
      # { 'alias' : 'Class.trait' }
      aliases = {}
      for alias, cls_trait in self.aliases.items():
          cls, trait = cls_trait.split(".", 1)
          children = mro_tree[cls]
          if len(children) == 1:
              # exactly one descendent, promote alias
              cls = children[0]
          aliases[alias] = ".".join([cls, trait])
  
      # flatten flags, which are of the form:
      # { 'key' : ({'Cls' : {'trait' : value}}, 'help')}
      flags = {}
      for key, (flagdict, help) in self.flags.items():
          newflag = {}
          for cls, subdict in flagdict.items():
              children = mro_tree[cls]
              # exactly one descendent, promote flag section
              if len(children) == 1:
                  cls = children[0]
              newflag[cls] = subdict
          flags[key] = (newflag, help)
      return flags, aliases
  
imports: from __future__ import print_function
  from copy import deepcopy
  import json
  import logging
  import os
  import re
  import sys
  from collections import defaultdict, OrderedDict
  from decorator import decorator
  from traitlets.config.configurable import Configurable, SingletonConfigurable
  from traitlets.config.loader import KVArgParseConfigLoader, PyFileConfigLoader, Config, ArgumentError, ConfigFileNotFound, JSONFileConfigLoader
  from traitlets.traitlets import Bool, Unicode, List, Enum, Dict, Instance, TraitError, observe, observe_compat, default
  from ipython_genutils.importstring import import_item
  from ipython_genutils.text import indent, wrap_paragraphs, dedent
  from ipython_genutils import py3compat
  import six
label_desc: Use image node_id 20 for calling the Application obj's underlying member method code with example usage: obj.flatten_flags() and returns: flags,  aliases