code: def with_polymorphic(
      base: Union[Type[_O], Mapper[_O]],
      classes: Union[Literal["*"], Iterable[Type[Any]]],
      selectable: Union[Literal[False, None], FromClause] = False,
      flat: bool = False,
      polymorphic_on: Optional[ColumnElement[Any]] = None,
      aliased: bool = False,
      innerjoin: bool = False,
      adapt_on_names: bool = False,
      _use_mapper_path: bool = False,
  ) -> AliasedClass[_O]:
      """Produce an :class:`.AliasedClass` construct which specifies
      columns for descendant mappers of the given base.
  
      Using this method will ensure that each descendant mapper's
      tables are included in the FROM clause, and will allow filter()
      criterion to be used against those tables.  The resulting
      instances will also have those columns already loaded so that
      no "post fetch" of those columns will be required.
  
      .. seealso::
  
          :ref:`with_polymorphic` - full discussion of
          :func:`_orm.with_polymorphic`.
  
      :param base: Base class to be aliased.
  
      :param classes: a single class or mapper, or list of
          class/mappers, which inherit from the base class.
          Alternatively, it may also be the string ``'*'``, in which case
          all descending mapped classes will be added to the FROM clause.
  
      :param aliased: when True, the selectable will be aliased.   For a
          JOIN, this means the JOIN will be SELECTed from inside of a subquery
          unless the :paramref:`_orm.with_polymorphic.flat` flag is set to
          True, which is recommended for simpler use cases.
  
      :param flat: Boolean, will be passed through to the
       :meth:`_expression.FromClause.alias` call so that aliases of
       :class:`_expression.Join` objects will alias the individual tables
       inside the join, rather than creating a subquery.  This is generally
       supported by all modern databases with regards to right-nested joins
       and generally produces more efficient queries.  Setting this flag is
       recommended as long as the resulting SQL is functional.
  
      :param selectable: a table or subquery that will
          be used in place of the generated FROM clause. This argument is
          required if any of the desired classes use concrete table
          inheritance, since SQLAlchemy currently cannot generate UNIONs
          among tables automatically. If used, the ``selectable`` argument
          must represent the full set of tables and columns mapped by every
          mapped class. Otherwise, the unaccounted mapped columns will
          result in their table being appended directly to the FROM clause
          which will usually lead to incorrect results.
  
          When left at its default value of ``False``, the polymorphic
          selectable assigned to the base mapper is used for selecting rows.
          However, it may also be passed as ``None``, which will bypass the
          configured polymorphic selectable and instead construct an ad-hoc
          selectable for the target classes given; for joined table inheritance
          this will be a join that includes all target mappers and their
          subclasses.
  
      :param polymorphic_on: a column to be used as the "discriminator"
          column for the given selectable. If not given, the polymorphic_on
          attribute of the base classes' mapper will be used, if any. This
          is useful for mappings that don't have polymorphic loading
          behavior by default.
  
      :param innerjoin: if True, an INNER JOIN will be used.  This should
         only be specified if querying for one specific subtype only
  
      :param adapt_on_names: Passes through the
        :paramref:`_orm.aliased.adapt_on_names`
        parameter to the aliased object.  This may be useful in situations where
        the given selectable is not directly related to the existing mapped
        selectable.
  
        .. versionadded:: 1.4.33
  
      """
      return AliasedInsp._with_polymorphic_factory(
          base,
          classes,
          selectable=selectable,
          flat=flat,
          polymorphic_on=polymorphic_on,
          adapt_on_names=adapt_on_names,
          aliased=aliased,
          innerjoin=innerjoin,
          _use_mapper_path=_use_mapper_path,
      )
  
imports: from __future__ import annotations
  import typing
  from typing import Any
  from typing import Callable
  from typing import Collection
  from typing import Iterable
  from typing import NoReturn
  from typing import Optional
  from typing import overload
  from typing import Type
  from typing import TYPE_CHECKING
  from typing import Union
  from .None import mapperlib
  from ._typing import _O
  from .descriptor_props import Composite
  from .descriptor_props import Synonym
  from .interfaces import _AttributeOptions
  from .properties import MappedColumn
  from .properties import MappedSQLExpression
  from .query import AliasOption
  from .relationships import _RelationshipArgumentType
  from .relationships import _RelationshipSecondaryArgument
  from .relationships import Relationship
  from .relationships import RelationshipProperty
  from .session import Session
  from .util import _ORMJoin
  from .util import AliasedClass
  from .util import AliasedInsp
  from .util import LoaderCriteriaOption
  from ..None import sql
  from ..None import util
  from ..exc import InvalidRequestError
  from ..sql._typing import _no_kw
  from ..sql.base import _NoArg
  from ..sql.base import SchemaEventTarget
  from ..sql.schema import _InsertSentinelColumnDefault
  from ..sql.schema import SchemaConst
  from ..sql.selectable import FromClause
  from ..util.typing import Annotated
  from ..util.typing import Literal
label_desc: Use image node_id 23 for calling a global function with example usage: with_polymorphic(base, classes, selectable, flat, polymorphic_on, aliased, innerjoin, adapt_on_names, _use_mapper_path) and returns: AliasedInsp