]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix docs for `case` expression to match new syntax (#9279)
authorAbdulhaq Emhemmed <el.ingeniero09@gmail.com>
Fri, 10 Feb 2023 21:56:30 +0000 (22:56 +0100)
committerGitHub <noreply@github.com>
Fri, 10 Feb 2023 21:56:30 +0000 (22:56 +0100)
* Fix docs for `case` expression to match new syntax

Previously (before v1.4), the `whens` arg (when `value` is *not* used) used to be a list of
conditions (a 2 item-tuple of condition + value). From v1.4, these are passed
as positional args and the old syntax is not supported anymore.

* Fix long lines

lib/sqlalchemy/ext/compiler.py
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/sql/_elements_constructors.py

index 54a99cceda8045536512c38f48d158c8ba2468db..39a554103050f4210ef6520de0298ac7086c1ad7 100644 (file)
@@ -409,7 +409,7 @@ accommodates two arguments::
     @compiles(greatest, 'oracle')
     def case_greatest(element, compiler, **kw):
         arg1, arg2 = list(element.clauses)
-        return compiler.process(case([(arg1 > arg2, arg1)], else_=arg2), **kw)
+        return compiler.process(case((arg1 > arg2, arg1), else_=arg2), **kw)
 
 Example usage::
 
index 092ab1cdaae1d98502be697a16f779a610f8b2fa..c0ff2ed10e601a39e27a47abb9b302fbe10c4133 100644 (file)
@@ -565,10 +565,10 @@ class Mapper(
                 discriminator: Mapped[str] = mapped_column(String(50))
 
                 __mapper_args__ = {
-                    "polymorphic_on":case([
+                    "polymorphic_on":case(
                         (discriminator == "EN", "engineer"),
                         (discriminator == "MA", "manager"),
-                    ], else_="employee"),
+                        else_="employee"),
                     "polymorphic_identity":"employee"
                 }
 
index 98f5a1cc6f4c131aaa46da558c0f557638a77dcb..5c7019718242937b1024343e79515e4f64a7f68c 100644 (file)
@@ -757,10 +757,10 @@ def case(
      .. versionchanged:: 1.4 the :func:`_sql.case`
         function now accepts the series of WHEN conditions positionally
 
-     In the first form, it accepts a list of 2-tuples; each 2-tuple
-     consists of ``(<sql expression>, <value>)``, where the SQL
-     expression is a boolean expression and "value" is a resulting value,
-     e.g.::
+     In the first form, it accepts multiple 2-tuples passed as positional
+     arguments; each 2-tuple consists of ``(<sql expression>, <value>)``,
+     where the SQL expression is a boolean expression and "value" is a
+     resulting value, e.g.::
 
         case(
             (users_table.c.name == 'wendy', 'W'),