from __future__ import annotations
+import builtins
import re
import sys
import typing
if "." in name:
return eval_expression(name, module_name, locals_=locals_)
+ # Try builtins first, to handle `list`, `set` or `dict`, etc.
+ try:
+ return builtins.__dict__[name]
+ except KeyError:
+ pass
+
try:
base_globals: Dict[str, Any] = sys.modules[module_name].__dict__
except KeyError as ke:
decl_base.registry.configure()
- def test_14_style_anno_accepted_w_allow_unmapped(self):
- """test for #8692"""
+ @testing.combinations(
+ ("list", testing.requires.python310),
+ ("List",),
+ ("set", testing.requires.python310),
+ ("Set",),
+ argnames="collection_type",
+ )
+ def test_14_style_anno_accepted_w_allow_unmapped(self, collection_type):
+ """test for #8692 and #10385"""
class Base(DeclarativeBase):
__allow_unmapped__ = True
id: Mapped[int] = mapped_column(primary_key=True)
data: str = Column(String)
- bs: List["B"] = relationship("B", back_populates="a") # noqa: F821
+
+ if collection_type == "list":
+ bs: list["B"] = relationship( # noqa: F821
+ "B",
+ back_populates="a",
+ )
+ elif collection_type == "List":
+ bs: List["B"] = relationship( # noqa: F821
+ "B",
+ back_populates="a",
+ )
+ elif collection_type == "set":
+ bs: set["B"] = relationship( # noqa: F821
+ "B",
+ back_populates="a",
+ )
+ elif collection_type == "Set":
+ bs: Set["B"] = relationship( # noqa: F821
+ "B",
+ back_populates="a",
+ )
+ else:
+ collection_type.fail()
class B(Base):
__tablename__ = "b"
decl_base.registry.configure()
- def test_14_style_anno_accepted_w_allow_unmapped(self):
- """test for #8692"""
+ @testing.combinations(
+ ("list", testing.requires.python310),
+ ("List",),
+ ("set", testing.requires.python310),
+ ("Set",),
+ argnames="collection_type",
+ )
+ def test_14_style_anno_accepted_w_allow_unmapped(self, collection_type):
+ """test for #8692 and #10385"""
class Base(DeclarativeBase):
__allow_unmapped__ = True
id: Mapped[int] = mapped_column(primary_key=True)
data: str = Column(String)
- bs: List["B"] = relationship("B", back_populates="a") # noqa: F821
+
+ if collection_type == "list":
+ bs: list["B"] = relationship( # noqa: F821
+ "B",
+ back_populates="a",
+ )
+ elif collection_type == "List":
+ bs: List["B"] = relationship( # noqa: F821
+ "B",
+ back_populates="a",
+ )
+ elif collection_type == "set":
+ bs: set["B"] = relationship( # noqa: F821
+ "B",
+ back_populates="a",
+ )
+ elif collection_type == "Set":
+ bs: Set["B"] = relationship( # noqa: F821
+ "B",
+ back_populates="a",
+ )
+ else:
+ collection_type.fail()
class B(Base):
__tablename__ = "b"