code: def get_all_dependencies(metadata: MetaData,
                           extra_dependencies: List[TableDependency] = None,
                           sort: bool = True) \
          -> List[TableDependency]:
      
      extra_dependencies = extra_dependencies or []  # type: List[TableDependency]  # noqa
      for td in extra_dependencies:
          td.set_metadata_if_none(metadata)
      dependencies = set([td.sqla_tuple() for td in extra_dependencies])
  
      tables = list(metadata.tables.values())  # type: List[Table]
  
      for table in tables:
          for fkc in table.foreign_key_constraints:
              if fkc.use_alter is True:
                  # http://docs.sqlalchemy.org/en/latest/core/constraints.html#sqlalchemy.schema.ForeignKeyConstraint.params.use_alter  # noqa
                  continue
  
              dependent_on = fkc.referred_table
              if dependent_on is not table:
                  dependencies.add((dependent_on, table))
  
          if hasattr(table, "_extra_dependencies"):
              # noinspection PyProtectedMember
              dependencies.update(
                  (parent, table) for parent in table._extra_dependencies
              )
  
      dependencies = [
          TableDependency(parent_table=parent, child_table=child)
          for parent, child in dependencies
      ]
      if sort:
          dependencies.sort(key=lambda td_: (td_.parent_tablename,
                                             td_.child_tablename))
      return dependencies
docs: Describes how the tables found in the metadata depend on each other.
      (If table B contains a foreign key to table A, for example, then B depends
      on A.)
  
      Args:
          metadata: the metadata to inspect
          extra_dependencies: additional table dependencies to specify manually
          sort: sort into alphabetical order of (parent, child) table names?
  
      Returns:
          a list of :class:`TableDependency` objects
  
      See :func:`sort_tables_and_constraints` for method.