]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
moved all fixed instances of list[] -> List[]
authorHarry Lees <harry.lees@gmail.com>
Tue, 31 Jan 2023 12:58:19 +0000 (12:58 +0000)
committerHarry Lees <harry.lees@gmail.com>
Tue, 31 Jan 2023 13:05:51 +0000 (13:05 +0000)
12 files changed:
doc/build/changelog/migration_20.rst
doc/build/orm/basic_relationships.rst
doc/build/orm/collection_api.rst
doc/build/orm/declarative_styles.rst
doc/build/orm/extensions/associationproxy.rst
doc/build/orm/extensions/asyncio.rst
doc/build/orm/inheritance.rst
doc/build/orm/large_collections.rst
doc/build/orm/queryguide/_inheritance_setup.rst
doc/build/orm/queryguide/relationships.rst
doc/build/orm/quickstart.rst
doc/build/tutorial/orm_related_objects.rst

index 51e34955ee46328656eda5a41ad9c516121b172e..604d59e083beaa8f60d2182d02f403700e0d062b 100644 (file)
@@ -471,7 +471,7 @@ are subject to these errors, as would occur in the example below::
         id: int = Column(Integer, primary_key=True)
 
         # will raise
-        bars: list["Bar"] = relationship("Bar", back_populates="foo")
+        bars: List["Bar"] = relationship("Bar", back_populates="foo")
 
 
     class Bar(Base):
@@ -519,7 +519,7 @@ that descend from ``Base``::
 
         id: int = Column(Integer, primary_key=True)
 
-        bars: list["Bar"] = relationship("Bar", back_populates="foo")
+        bars: List["Bar"] = relationship("Bar", back_populates="foo")
 
 
     class Bar(Base):
index 28c1c65bfd9dc681e85191aee512e3be8b8daa76..116c6b6d4bb8793c760057b36b085f4cdda80141 100644 (file)
@@ -10,6 +10,7 @@ based on the use of the :class:`_orm.Mapped` annotation type.
 The setup for each of the following sections is as follows::
 
     from __future__ import annotations
+    from typing import List
 
     from sqlalchemy import ForeignKey
     from sqlalchemy import Integer
@@ -40,7 +41,7 @@ which is the most modern form of SQLAlchemy Declarative mapping::
         __tablename__ = "parent_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list["Child"]] = relationship(back_populates="parent")
+        children: Mapped[List["Child"]] = relationship(back_populates="parent")
 
 
     class Child(Base):
@@ -114,7 +115,7 @@ a collection of items represented by the child::
         __tablename__ = "parent_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list["Child"]] = relationship()
+        children: Mapped[List["Child"]] = relationship()
 
 
     class Child(Base):
@@ -134,7 +135,7 @@ as the value for :paramref:`_orm.relationship.back_populates` on the other::
         __tablename__ = "parent_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list["Child"]] = relationship(back_populates="parent")
+        children: Mapped[List["Child"]] = relationship(back_populates="parent")
 
 
     class Child(Base):
@@ -236,7 +237,7 @@ as the value for :paramref:`_orm.relationship.back_populates` on the other::
         __tablename__ = "child_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        parents: Mapped[list["Parent"]] = relationship(back_populates="child")
+        parents: Mapped[List["Parent"]] = relationship(back_populates="child")
 
 .. _relationship_patterns_nullable_m2o:
 
@@ -265,7 +266,7 @@ case the configuration would look like::
         __tablename__ = "child_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        parents: Mapped[list["Parent"]] = relationship(back_populates="child")
+        parents: Mapped[List["Parent"]] = relationship(back_populates="child")
 
 Above, the column for ``Parent.child_id`` will be created in DDL to allow
 ``NULL`` values. When using :func:`_orm.mapped_column` with explicit typing
@@ -297,7 +298,7 @@ for background on this behavior.
           __tablename__ = "child_table"
 
           id: Mapped[int] = mapped_column(primary_key=True)
-          parents: Mapped[list[Parent]] = relationship(back_populates="child")
+          parents: Mapped[List[Parent]] = relationship(back_populates="child")
 
 .. _relationships_one_to_one:
 
@@ -423,7 +424,7 @@ with which to link::
         __tablename__ = "left_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list[Child]] = relationship(secondary=association_table)
+        children: Mapped[List[Child]] = relationship(secondary=association_table)
 
 
     class Child(Base):
@@ -485,7 +486,7 @@ for each :func:`_orm.relationship` specify the common association table::
         __tablename__ = "left_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list[Child]] = relationship(
+        children: Mapped[List[Child]] = relationship(
             secondary=association_table, back_populates="parents"
         )
 
@@ -494,7 +495,7 @@ for each :func:`_orm.relationship` specify the common association table::
         __tablename__ = "right_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        parents: Mapped[list[Parent]] = relationship(
+        parents: Mapped[List[Parent]] = relationship(
             secondary=association_table, back_populates="children"
         )
 
@@ -650,7 +651,7 @@ from ``Parent`` to ``Child`` makes explicit use of ``Association``::
     class Parent(Base):
         __tablename__ = "left_table"
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list["Association"]] = relationship()
+        children: Mapped[List["Association"]] = relationship()
 
 
     class Child(Base):
@@ -688,13 +689,13 @@ constructs, linked to the existing ones using :paramref:`_orm.relationship.back_
     class Parent(Base):
         __tablename__ = "left_table"
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list["Association"]] = relationship(back_populates="parent")
+        children: Mapped[List["Association"]] = relationship(back_populates="parent")
 
 
     class Child(Base):
         __tablename__ = "right_table"
         id: Mapped[int] = mapped_column(primary_key=True)
-        parents: Mapped[list["Association"]] = relationship(back_populates="child")
+        parents: Mapped[List["Association"]] = relationship(back_populates="child")
 
 Working with the association pattern in its direct form requires that child
 objects are associated with an association instance before being appended to
@@ -789,12 +790,12 @@ and ``Child.parent_associations -> Association.parent``::
         id: Mapped[int] = mapped_column(primary_key=True)
 
         # many-to-many relationship to Child, bypassing the `Association` class
-        children: Mapped[list["Child"]] = relationship(
+        children: Mapped[List["Child"]] = relationship(
             secondary="association_table", back_populates="parents"
         )
 
         # association between Parent -> Association -> Child
-        child_associations: Mapped[list["Association"]] = relationship(
+        child_associations: Mapped[List["Association"]] = relationship(
             back_populates="parent"
         )
 
@@ -805,12 +806,12 @@ and ``Child.parent_associations -> Association.parent``::
         id: Mapped[int] = mapped_column(primary_key=True)
 
         # many-to-many relationship to Parent, bypassing the `Association` class
-        parents: Mapped[list["Parent"]] = relationship(
+        parents: Mapped[List["Parent"]] = relationship(
             secondary="association_table", back_populates="children"
         )
 
         # association between Child -> Association -> Parent
-        parent_associations: Mapped[list["Association"]] = relationship(
+        parent_associations: Mapped[List["Association"]] = relationship(
             back_populates="child"
         )
 
@@ -858,12 +859,12 @@ additional association columns, as below::
         id: Mapped[int] = mapped_column(primary_key=True)
 
         # many-to-many relationship to Child, bypassing the `Association` class
-        children: Mapped[list["Child"]] = relationship(
+        children: Mapped[List["Child"]] = relationship(
             secondary="association_table", back_populates="parents", viewonly=True
         )
 
         # association between Parent -> Association -> Child
-        child_associations: Mapped[list["Association"]] = relationship(
+        child_associations: Mapped[List["Association"]] = relationship(
             back_populates="parent"
         )
 
@@ -874,12 +875,12 @@ additional association columns, as below::
         id: Mapped[int] = mapped_column(primary_key=True)
 
         # many-to-many relationship to Parent, bypassing the `Association` class
-        parents: Mapped[list["Parent"]] = relationship(
+        parents: Mapped[List["Parent"]] = relationship(
             secondary="association_table", back_populates="children", viewonly=True
         )
 
         # association between Child -> Association -> Parent
-        parent_associations: Mapped[list["Association"]] = relationship(
+        parent_associations: Mapped[List["Association"]] = relationship(
             back_populates="child"
         )
 
@@ -919,7 +920,7 @@ at runtime only as a string::
     class Parent(Base):
         # ...
 
-        children: Mapped[list["Child"]] = relationship(back_populates="parent")
+        children: Mapped[List["Child"]] = relationship(back_populates="parent")
 
 
     class Child(Base):
@@ -971,7 +972,7 @@ package, including expression functions like :func:`_sql.desc` and
     class Parent(Base):
         # ...
 
-        children: Mapped[list["Child"]] = relationship(
+        children: Mapped[List["Child"]] = relationship(
             order_by="desc(Child.email_address)",
             primaryjoin="Parent.id == Child.parent_id",
         )
@@ -983,7 +984,7 @@ within any of these string expressions::
     class Parent(Base):
         # ...
 
-        children: Mapped[list["myapp.mymodel.Child"]] = relationship(
+        children: Mapped[List["myapp.mymodel.Child"]] = relationship(
             order_by="desc(myapp.mymodel.Child.email_address)",
             primaryjoin="myapp.mymodel.Parent.id == myapp.mymodel.Child.parent_id",
         )
@@ -1004,7 +1005,7 @@ name within the :class:`_orm.registry`::
     class Parent(Base):
         # ...
 
-        children: Mapped[list["Child"]] = relationship(
+        children: Mapped[List["Child"]] = relationship(
             "myapp.mymodel.Child",
             order_by="desc(myapp.mymodel.Child.email_address)",
             primaryjoin="myapp.mymodel.Parent.id == myapp.mymodel.Child.parent_id",
@@ -1018,7 +1019,7 @@ we can specify ``model1.Child`` or ``model2.Child``::
     class Parent(Base):
         # ...
 
-        children: Mapped[list["Child"]] = relationship(
+        children: Mapped[List["Child"]] = relationship(
             "model1.Child",
             order_by="desc(mymodel1.Child.email_address)",
             primaryjoin="Parent.id == model1.Child.parent_id",
@@ -1045,7 +1046,7 @@ like the following::
     class Parent(Base):
         # ...
 
-        children: Mapped[list["Child"]] = relationship(
+        children: Mapped[List["Child"]] = relationship(
             _resolve_child_model(),
             order_by=lambda: desc(_resolve_child_model().email_address),
             primaryjoin=lambda: Parent.id == _resolve_child_model().parent_id,
@@ -1151,7 +1152,7 @@ using a lambda as::
         __tablename__ = "left_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list["Child"]] = relationship(
+        children: Mapped[List["Child"]] = relationship(
             "Child", secondary=lambda: association_table
         )
 
@@ -1165,7 +1166,7 @@ the :class:`.MetaData` collection::
         __tablename__ = "left_table"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list["Child"]] = relationship(secondary="association_table")
+        children: Mapped[List["Child"]] = relationship(secondary="association_table")
 
 .. warning:: When passed as a string,
     :paramref:`_orm.relationship.secondary` argument is interpreted using Python's
index aba0ca104c8c42871ed79ae41e244f8afa4af29e..f580b26c939d69d2692678dd2cdd12cc760e1eec 100644 (file)
@@ -47,7 +47,7 @@ below where ``list`` is used::
         parent_id: Mapped[int] = mapped_column(primary_key=True)
 
         # use a list
-        children: Mapped[list["Child"]] = relationship()
+        children: Mapped[List["Child"]] = relationship()
 
 
     class Child(Base):
index b644ac41817c2c7f02b3ce2af815469f89922581..a02391004b5a36e9948496c9bb103d22e2314351 100644 (file)
@@ -75,7 +75,7 @@ of the base::
         nickname: Mapped[Optional[str]] = mapped_column(String(64))
         create_date: Mapped[datetime] = mapped_column(insert_default=func.now())
 
-        addresses: Mapped[list["Address"]] = relationship(back_populates="user")
+        addresses: Mapped[List["Address"]] = relationship(back_populates="user")
 
 
     class Address(Base):
@@ -126,6 +126,7 @@ previous section, using the :meth:`_orm.registry.mapped`
 decorator rather than using the :class:`_orm.DeclarativeBase` superclass::
 
     from datetime import datetime
+    from typing import List
     from typing import Optional
 
     from sqlalchemy import ForeignKey
@@ -150,7 +151,7 @@ decorator rather than using the :class:`_orm.DeclarativeBase` superclass::
         nickname: Mapped[Optional[str]] = mapped_column(String(64))
         create_date: Mapped[datetime] = mapped_column(insert_default=func.now())
 
-        addresses: Mapped[list["Address"]] = relationship(back_populates="user")
+        addresses: Mapped[List["Address"]] = relationship(back_populates="user")
 
 
     @mapper_registry.mapped
index 0f96c955d66623303d2cb9e68ebc0da4c7e8da94..54e18c55a4b9437f7363dd6c95ec16373f0a3206 100644 (file)
@@ -52,13 +52,13 @@ exception of an extra attribute added to the ``User`` class called
         __tablename__ = "user"
         id: Mapped[int] = mapped_column(primary_key=True)
         name: Mapped[str] = mapped_column(String(64))
-        kw: Mapped[list[Keyword]] = relationship(secondary=lambda: user_keyword_table)
+        kw: Mapped[List[Keyword]] = relationship(secondary=lambda: user_keyword_table)
 
         def __init__(self, name: str):
             self.name = name
 
         # proxy the 'keyword' attribute from the 'kw' relationship
-        keywords: AssociationProxy[list[str]] = association_proxy("kw", "keyword")
+        keywords: AssociationProxy[List[str]] = association_proxy("kw", "keyword")
 
 
     class Keyword(Base):
@@ -150,7 +150,7 @@ using a lambda as is typical::
         ...
 
         # use Keyword(keyword=kw) on append() events
-        keywords: AssociationProxy[list[str]] = association_proxy(
+        keywords: AssociationProxy[List[str]] = association_proxy(
             "kw", "keyword", creator=lambda kw: Keyword(keyword=kw)
         )
 
@@ -203,14 +203,14 @@ collection of ``User`` to the ``.keyword`` attribute present on each
         id: Mapped[int] = mapped_column(primary_key=True)
         name: Mapped[str] = mapped_column(String(64))
 
-        user_keyword_associations: Mapped[list[UserKeywordAssociation]] = relationship(
+        user_keyword_associations: Mapped[List[UserKeywordAssociation]] = relationship(
             back_populates="user",
             cascade="all, delete-orphan",
         )
 
         # association proxy of "user_keyword_associations" collection
         # to "keyword" attribute
-        keywords: AssociationProxy[list[Keyword]] = association_proxy(
+        keywords: AssociationProxy[List[Keyword]] = association_proxy(
             "user_keyword_associations",
             "keyword",
             creator=lambda keyword: UserKeywordAssociation(keyword=Keyword(keyword)),
@@ -547,7 +547,7 @@ to a related object, as in the example mapping below::
         )
 
         # column-targeted association proxy
-        special_keys: AssociationProxy[list[str]] = association_proxy(
+        special_keys: AssociationProxy[List[str]] = association_proxy(
             "user_keyword_associations", "special_key"
         )
 
index 45da8ef36e5b23b51df4a4803f0c8626168c016e..94aa609145340b776951eb537f504f6b1344b1fa 100644 (file)
@@ -150,6 +150,7 @@ illustrates a complete example including mapper and session configuration::
 
     import asyncio
     import datetime
+    from typing import List
 
     from sqlalchemy import ForeignKey
     from sqlalchemy import func
@@ -174,7 +175,7 @@ illustrates a complete example including mapper and session configuration::
         id: Mapped[int] = mapped_column(primary_key=True)
         data: Mapped[str]
         create_date: Mapped[datetime.datetime] = mapped_column(server_default=func.now())
-        bs: Mapped[list[B]] = relationship()
+        bs: Mapped[List[B]] = relationship()
 
 
     class B(Base):
index d35967e4ca5086f1f8973dee67a66584c21e7a95..e99bc1df62ccea9380d2c4160bdb7caf14505b75 100644 (file)
@@ -186,7 +186,7 @@ and ``Employee``::
         __tablename__ = "company"
         id: Mapped[int] = mapped_column(primary_key=True)
         name: Mapped[str]
-        employees: Mapped[list[Employee]] = relationship(back_populates="company")
+        employees: Mapped[List[Employee]] = relationship(back_populates="company")
 
 
     class Employee(Base):
@@ -220,7 +220,7 @@ established between the ``Manager`` and ``Company`` classes::
         __tablename__ = "company"
         id: Mapped[int] = mapped_column(primary_key=True)
         name: Mapped[str]
-        managers: Mapped[list[Manager]] = relationship(back_populates="company")
+        managers: Mapped[List[Manager]] = relationship(back_populates="company")
 
 
     class Employee(Base):
@@ -481,7 +481,7 @@ relationship::
         __tablename__ = "company"
         id: Mapped[int] = mapped_column(primary_key=True)
         name: Mapped[str]
-        employees: Mapped[list[Employee]] = relationship(back_populates="company")
+        employees: Mapped[List[Employee]] = relationship(back_populates="company")
 
 
     class Employee(Base):
@@ -522,7 +522,7 @@ or subclasses::
         __tablename__ = "company"
         id: Mapped[int] = mapped_column(primary_key=True)
         name: Mapped[str]
-        managers: Mapped[list[Manager]] = relationship(back_populates="company")
+        managers: Mapped[List[Manager]] = relationship(back_populates="company")
 
 
     class Employee(Base):
index 8553fae42e56d7667569375c9545dac32ddd94c0..afe3c506c9599c5419edb98e02573082036baed0 100644 (file)
@@ -631,7 +631,7 @@ emit a lazy load::
 
         # ...
 
-        children: Mapped[list[MyRelatedClass]] = relationship(lazy="raise")
+        children: Mapped[List[MyRelatedClass]] = relationship(lazy="raise")
 
 Above, attribute access on the ``children`` collection will raise an exception
 if it was not previously populated.  This includes read access but for
index c98a83035a0bf62088039fe1eee4bb5a5c9a9d43..e429b179f25b008c69bae76a51e597400a94f683 100644 (file)
@@ -11,6 +11,7 @@ the :ref:`queryguide_toplevel`.
 ..  sourcecode:: python
 
 
+    >>> from typing import List
     >>> from sqlalchemy import create_engine
     >>> from sqlalchemy import ForeignKey
     >>> from sqlalchemy.orm import DeclarativeBase
@@ -26,7 +27,7 @@ the :ref:`queryguide_toplevel`.
     ...     __tablename__ = "company"
     ...     id: Mapped[int] = mapped_column(primary_key=True)
     ...     name: Mapped[str]
-    ...     employees: Mapped[list["Employee"]] = relationship(back_populates="company")
+    ...     employees: Mapped[List["Employee"]] = relationship(back_populates="company")
     >>>
     >>> class Employee(Base):
     ...     __tablename__ = "employee"
@@ -48,7 +49,7 @@ the :ref:`queryguide_toplevel`.
     ...     __tablename__ = "manager"
     ...     id: Mapped[int] = mapped_column(ForeignKey("employee.id"), primary_key=True)
     ...     manager_name: Mapped[str]
-    ...     paperwork: Mapped[list["Paperwork"]] = relationship()
+    ...     paperwork: Mapped[List["Paperwork"]] = relationship()
     ...     __mapper_args__ = {
     ...         "polymorphic_identity": "manager",
     ...     }
index 593fe995b2077363fd0070757bfd24f248da9d1c..9c621ea9ac1107e66a63d51f2747e0accea72b04 100644 (file)
@@ -124,6 +124,8 @@ The example below illustrates the relationship example at
 relationship to use :ref:`selectin_eager_loading` when a SELECT
 statement for ``Parent`` objects is emitted::
 
+    from typing import List
+
     from sqlalchemy import ForeignKey
     from sqlalchemy.orm import DeclarativeBase
     from sqlalchemy.orm import Mapped
@@ -139,7 +141,7 @@ statement for ``Parent`` objects is emitted::
         __tablename__ = "parent"
 
         id: Mapped[int] = mapped_column(primary_key=True)
-        children: Mapped[list["Child"]] = relationship(lazy="selectin")
+        children: Mapped[List["Child"]] = relationship(lazy="selectin")
 
 
     class Child(Base):
index a4531e8d345eb0a56ce4c33a56600e3fdc3d91d2..eee91358803320ec3163010c9d2d08bc98eb16c1 100644 (file)
@@ -27,6 +27,7 @@ which we will be querying from the database.  This structure, known as a
 Python object model, as well as :term:`database metadata` that describes
 real SQL tables that exist, or will exist, in a particular database::
 
+    >>> from typing import List
     >>> from typing import Optional
     >>> from sqlalchemy import ForeignKey
     >>> from sqlalchemy import String
@@ -45,7 +46,7 @@ real SQL tables that exist, or will exist, in a particular database::
     ...     name: Mapped[str] = mapped_column(String(30))
     ...     fullname: Mapped[Optional[str]]
     ...
-    ...     addresses: Mapped[list["Address"]] = relationship(
+    ...     addresses: Mapped[List["Address"]] = relationship(
     ...         back_populates="user", cascade="all, delete-orphan"
     ...     )
     ...
index bd1fae131c98a53adf9fe4710a971ae17df7b5cb..902881c782172c3491303fce0db7494c218a8b92 100644 (file)
@@ -34,7 +34,7 @@ and other directives:
 
         # ... mapped_column() mappings
 
-        addresses: Mapped[list["Address"]] = relationship(back_populates="user")
+        addresses: Mapped[List["Address"]] = relationship(back_populates="user")
 
 
     class Address(Base):
@@ -400,7 +400,7 @@ the :paramref:`_orm.relationship.lazy` option, e.g.:
     class User(Base):
         __tablename__ = "user_account"
 
-        addresses: Mapped[list["Address"]] = relationship(
+        addresses: Mapped[List["Address"]] = relationship(
             back_populates="user", lazy="selectin"
         )
 
@@ -629,7 +629,7 @@ relationship will never try to emit SQL:
     >>> class User(Base):
     ...     __tablename__ = "user_account"
     ...     id: Mapped[int] = mapped_column(primary_key=True)
-    ...     addresses: Mapped[list["Address"]] = relationship(
+    ...     addresses: Mapped[List["Address"]] = relationship(
     ...         back_populates="user", lazy="raise_on_sql"
     ...     )