def _determine_clashing_namespaces(self, py_namespaces_by_target):
    """Check for any overlapping namespaces."""
    namespaces_by_files = defaultdict(list)
    for target, all_namespaces in py_namespaces_by_target.items():
      for (path, namespace) in all_namespaces:
        namespaces_by_files[namespace].append((target, path))

    clashing_namespaces = {
      namespace: all_paths
      for namespace, all_paths in namespaces_by_files.items()
      if len(all_paths) > 1
    }
    if clashing_namespaces:
      pretty_printed_clashing = '\n'.join(
        '{}: [{}]'
        .format(
          namespace,
          ', '.join('({}, {})'.format(t.address.spec, path) for (t, path) in all_paths))
        for namespace, all_paths in clashing_namespaces.items())
      error = self.ClashingNamespaceError("""\
Clashing namespaces for python thrift library sources detected in build graph. This will silently
overwrite previously generated python sources with generated sources from thrift files declaring the
same python namespace. This is an upstream WONTFIX in thrift, see:
      https://issues.apache.org/jira/browse/THRIFT-515
Errors:
{}
""".format(pretty_printed_clashing))
      if self.get_options().strict:
        raise error
      else:
        self.context.log.warn(error)
    return namespaces_by_files
Check for any overlapping namespaces.