Issue 1:
Migrated issue, originally created by Michael Bayer (@zzzeek)

The orm/inheritance/abc_inheritance test relies upon fold_equivalents to spell out a UNION which builds a polymorphic discriminator column on the fly. This whole use case (i.e., joined table inheritance with no discriminator column) is more easily managed by using regular joined table inheritance, joining to all tables (i.e. with_polymorphic), and using a callable polymorphic_on function which checks for the presence of each joined table in order to determine the type. This is an easy enhancement and makes us compatible with Hibernate's joined table inheritance behavior. the whole fold_equivalents feature which nobody is using anyway can then be removed won't be needed in this case (a nicer fold_equivalents proposed in #1729).

Issue 2:
Describe the bug

It's not possible to create type-decorator for postgresql Range classes.

To Reproduce

from dataclasses import dataclass
from typing import Any

from sqlalchemy import create_engine, TypeDecorator, literal, select
from sqlalchemy.dialects.postgresql import INT4RANGE, Range

engine = create_engine('...')

@dataclass(frozen=True)
class MyRange:
start: int
end: int

class MyINT4RANGE(TypeDecorator):
cache_ok = True
impl = INT4RANGE

def process_bind_param(self, value: Any, dialect: Any) -> Any:
match value:
case MyRange(start, end):
return Range(start, end, bounds='[]')
case _:
return value

with engine.begin() as conn:
res = conn.scalar(select(literal(MyRange(1, 10), MyINT4RANGE)))

print(res)

Error

# Copy complete stack trace and error message here, including SQL log output if applicable.
Traceback (most recent call last):
File "/Users/yuriikarabas/PycharmProjects/sandbox/foo.py", line 29, in <module>
res = conn.scalar(select(literal(MyRange(1, 10), MyINT4RANGE)))
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1299, in scalar
return meth(
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 507, in _execute_on_scalar
return self._execute_on_connection(
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 489, in _execute_on_connection
return connection._execute_clauseelement(
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1630, in _execute_clauseelement
compiled_sql, extracted_params, cache_hit = elem._compile_w_cache(
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 654, in _compile_w_cache
compiled_sql = self._compiler(
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 289, in _compiler
return dialect.statement_compiler(dialect, self, **kw)
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 1137, in __init__
Compiled.__init__(self, dialect, statement, **kwargs)
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 664, in __init__
self.string = self.process(self.statement, **compile_kwargs)
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 701, in process
return obj._compiler_dispatch(self, **kwargs)
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/visitors.py", line 143, in _compiler_dispatch
return meth(self, **kw) # type: ignore # noqa: E501
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 4265, in visit_select
for c in [
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 4266, in <listcomp>
self._label_select_column(
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 4091, in _label_select_column
return result_expr._compiler_dispatch(self, **column_clause_args)
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/visitors.py", line 143, in _compiler_dispatch
return meth(self, **kw) # type: ignore # noqa: E501
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 2134, in visit_label
label.element._compiler_dispatch(
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/visitors.py", line 143, in _compiler_dispatch
return meth(self, **kw) # type: ignore # noqa: E501
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 3317, in visit_bindparam
ret = self.bindparam_string(
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/compiler.py", line 3481, in bindparam_string
type_impl = bindparam_type._unwrapped_dialect_impl(self.dialect)
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/type_api.py", line 1853, in _unwrapped_dialect_impl
return typ.load_dialect_impl(dialect).dialect_impl(dialect)
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/type_api.py", line 875, in dialect_impl
return self._dialect_info(dialect)["impl"]
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/sql/type_api.py", line 974, in _dialect_info
impl = self.adapt(type(self))
File "/Users/yuriikarabas/PycharmProjects/sandbox/venv310/lib/python3.10/site-packages/sqlalchemy/dialects/postgresql/ranges.py", line 702, in adapt
return type( # type: ignore
TypeError: duplicate base class INT4RANGERangeImpl

Versions

OS: macOS

Python: 3.10

SQLAlchemy: 2.0.0b4

Database: postgresql

DBAPI (eg: psycopg, cx_oracle, mysqlclient): psycopg

Additional context

Please, delete #9019 as it's a duplicate of this issue.