components/autofill_assistant/browser/devtools/devtools_api/client_api_generator.py
def InitializeDomainDependencies(json_api):
  """For each domain create list of domains given domain depends on,
  including itself."""

  direct_deps = collections.defaultdict(set)
  types_required = collections.defaultdict(set)

  def GetDomainDepsFromRefs(domain_name, json):
    if isinstance(json, list):
      for value in json:
        GetDomainDepsFromRefs(domain_name, value)
      return

    if not isinstance(json, dict):
      return
    for value in json.values():
      GetDomainDepsFromRefs(domain_name, value)

    if '$ref' in json:
      if '.' in json['$ref']:
        dep = json['$ref'].split('.')[0]
        direct_deps[domain_name].add(dep)
        types_required[domain_name].add(json['$ref'])

  for domain in json_api['domains']:
    direct_deps[domain['domain']] = set(domain.get('dependencies', []))
    types_required[domain['domain']] = set(domain.get('types_required', []))
    GetDomainDepsFromRefs(domain['domain'], domain)

  def TraverseDependencies(domain, deps):
    if domain in deps:
      return
    deps.add(domain)

    for dep in direct_deps[domain]:
      TraverseDependencies(dep, deps)

  for domain in json_api['domains']:
    domain_deps = set()
    TraverseDependencies(domain['domain'], domain_deps)
    if 'dependencies' in domain:
      domain['js_dependencies'] = domain['dependencies']
    else:
      domain['js_dependencies'] = []

    domain['js_forward_declarations'] = []
    for type in types_required[domain['domain']]:
      if not type.split('.')[0] in domain['js_dependencies']:
        domain['js_forward_declarations'].append(type)
    domain['dependencies'] = sorted(domain_deps)
For each domain create list of domains given domain depends on,
  including itself.
For each domain create list of domains given domain depends on,
including itself.
For each domain create list of domains given domain depends on including itself .
def InitializeDomainDependencies(json_api):
  direct_deps = collections.defaultdict(set)
  types_required = collections.defaultdict(set)
  def GetDomainDepsFromRefs(domain_name, json):
    if isinstance(json, list):
      for value in json:
        GetDomainDepsFromRefs(domain_name, value)
      return
    if not isinstance(json, dict):
      return
    for value in json.values():
      GetDomainDepsFromRefs(domain_name, value)
    if '$ref' in json:
      if '.' in json['$ref']:
        dep = json['$ref'].split('.')[0]
        direct_deps[domain_name].add(dep)
        types_required[domain_name].add(json['$ref'])
  for domain in json_api['domains']:
    direct_deps[domain['domain']] = set(domain.get('dependencies', []))
    types_required[domain['domain']] = set(domain.get('types_required', []))
    GetDomainDepsFromRefs(domain['domain'], domain)
  def TraverseDependencies(domain, deps):
    if domain in deps:
      return
    deps.add(domain)
    for dep in direct_deps[domain]:
      TraverseDependencies(dep, deps)
  for domain in json_api['domains']:
    domain_deps = set()
    TraverseDependencies(domain['domain'], domain_deps)
    if 'dependencies' in domain:
      domain['js_dependencies'] = domain['dependencies']
    else:
      domain['js_dependencies'] = []
    domain['js_forward_declarations'] = []
    for type in types_required[domain['domain']]:
      if not type.split('.')[0] in domain['js_dependencies']:
        domain['js_forward_declarations'].append(type)
    domain['dependencies'] = sorted(domain_deps)
def InitializeDomainDependencies ( json_api ) : direct_deps = collections . defaultdict ( set ) types_required = collections . defaultdict ( set ) def GetDomainDepsFromRefs ( domain_name , json ) : if isinstance ( json , list ) : for value in json : GetDomainDepsFromRefs ( domain_name , value ) return if not isinstance ( json , dict ) : return for value in json . values ( ) : GetDomainDepsFromRefs ( domain_name , value ) if '$ref' in json : if '.' in json [ '$ref' ] : dep = json [ '$ref' ] . split ( '.' ) [ 0 ] direct_deps [ domain_name ] . add ( dep ) types_required [ domain_name ] . add ( json [ '$ref' ] ) for domain in json_api [ 'domains' ] : direct_deps [ domain [ 'domain' ] ] = set ( domain . get ( 'dependencies' , [ ] ) ) types_required [ domain [ 'domain' ] ] = set ( domain . get ( 'types_required' , [ ] ) ) GetDomainDepsFromRefs ( domain [ 'domain' ] , domain ) def TraverseDependencies ( domain , deps ) : if domain in deps : return deps . add ( domain ) for dep in direct_deps [ domain ] : TraverseDependencies ( dep , deps ) for domain in json_api [ 'domains' ] : domain_deps = set ( ) TraverseDependencies ( domain [ 'domain' ] , domain_deps ) if 'dependencies' in domain : domain [ 'js_dependencies' ] = domain [ 'dependencies' ] else : domain [ 'js_dependencies' ] = [ ] domain [ 'js_forward_declarations' ] = [ ] for type in types_required [ domain [ 'domain' ] ] : if not type . split ( '.' ) [ 0 ] in domain [ 'js_dependencies' ] : domain [ 'js_forward_declarations' ] . append ( type ) domain [ 'dependencies' ] = sorted ( domain_deps )
For each domain create list of domains given domain depends on,
including itself.
For each domain create list of domains given domain depends on including itself .
"""For each domain create list of domains given domain depends on,
  including itself."""
json_api