--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 11831
+
+ Fixed regression caused by issue :ticket:`11814` which broke support for
+ certain flavors of :pep:`593` ``Annotated`` in the type_annotation_map when
+ builtin types such as ``list``, ``dict`` were used without an element type.
+ While this is an incomplete style of typing, these types nonetheless
+ previously would be located in the type_annotation_map correctly.
and similar for list, set
"""
+
if (
is_generic(type_)
- and type_.__origin__
+ and typing_get_origin(type_)
in (
dict,
set,
)
):
# compat with py3.10 and earlier
- return type_.__origin__.__class_getitem__( # type: ignore
+ return typing_get_origin(type_).__class_getitem__( # type: ignore
tuple(
[
ForwardRef(elem) if isinstance(elem, str) else elem
- for elem in type_.__args__
+ for elem in typing_get_args(type_)
]
)
)
Dict,
(str, str),
),
+ (list, None, testing.requires.python310),
+ (
+ List,
+ None,
+ ),
+ (dict, None, testing.requires.python310),
+ (
+ Dict,
+ None,
+ ),
id_="sa",
argnames="container_typ,args",
)
test #11814
+ test #11831, regression from #11814
"""
global TestType
if style.pep593:
- TestType = Annotated[container_typ[args], 0]
+ if args is None:
+ TestType = Annotated[container_typ, 0]
+ else:
+ TestType = Annotated[container_typ[args], 0]
elif style.alias:
- TestType = container_typ[args]
+ if args is None:
+ TestType = container_typ
+ else:
+ TestType = container_typ[args]
elif style.direct:
TestType = container_typ
- double_strings = args == (str, str)
class Base(DeclarativeBase):
if style.direct:
- if double_strings:
+ if args == (str, str):
type_annotation_map = {TestType[str, str]: JSON()}
+ elif args is None:
+ type_annotation_map = {TestType: JSON()}
else:
type_annotation_map = {TestType[str]: JSON()}
else:
id: Mapped[int] = mapped_column(primary_key=True)
if style.direct:
- if double_strings:
+ if args == (str, str):
data: Mapped[TestType[str, str]] = mapped_column()
+ elif args is None:
+ data: Mapped[TestType] = mapped_column()
else:
data: Mapped[TestType[str]] = mapped_column()
else:
Dict,
(str, str),
),
+ (list, None, testing.requires.python310),
+ (
+ List,
+ None,
+ ),
+ (dict, None, testing.requires.python310),
+ (
+ Dict,
+ None,
+ ),
id_="sa",
argnames="container_typ,args",
)
test #11814
+ test #11831, regression from #11814
"""
global TestType
if style.pep593:
- TestType = Annotated[container_typ[args], 0]
+ if args is None:
+ TestType = Annotated[container_typ, 0]
+ else:
+ TestType = Annotated[container_typ[args], 0]
elif style.alias:
- TestType = container_typ[args]
+ if args is None:
+ TestType = container_typ
+ else:
+ TestType = container_typ[args]
elif style.direct:
TestType = container_typ
- double_strings = args == (str, str)
class Base(DeclarativeBase):
if style.direct:
- if double_strings:
+ if args == (str, str):
type_annotation_map = {TestType[str, str]: JSON()}
+ elif args is None:
+ type_annotation_map = {TestType: JSON()}
else:
type_annotation_map = {TestType[str]: JSON()}
else:
id: Mapped[int] = mapped_column(primary_key=True)
if style.direct:
- if double_strings:
+ if args == (str, str):
data: Mapped[TestType[str, str]] = mapped_column()
+ elif args is None:
+ data: Mapped[TestType] = mapped_column()
else:
data: Mapped[TestType[str]] = mapped_column()
else: