code: def gen_relationships(obj) -> Generator[Tuple[str, RelationshipProperty, Type],
                                          None, None]:
      
      insp = inspect(obj)  # type: InstanceState
      # insp.mapper.relationships is of type
      # sqlalchemy.utils._collections.ImmutableProperties, which is basically
      # a sort of AttrDict.
      for attrname, rel_prop in insp.mapper.relationships.items():  # type: Tuple[str, RelationshipProperty]  # noqa
          # noinspection PyUnresolvedReferences
          related_class = rel_prop.mapper.class_
          # log.critical("gen_relationships: attrname={!r}, "
          #              "rel_prop={!r}, related_class={!r}, rel_prop.info={!r}",
          #              attrname, rel_prop, related_class, rel_prop.info)
          yield attrname, rel_prop, related_class
docs: Yields tuples of ``(attrname, RelationshipProperty, related_class)``
      for all relationships of an ORM object.
      The object 'obj' can be EITHER an instance OR a class.