Skip to content

Commit

Permalink
Merge "remove legacy select patterns" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzeek authored and Gerrit Code Review committed Dec 29, 2021
2 parents 9e3c8d0 + 97d81d3 commit 54875c2
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 667 deletions.
4 changes: 4 additions & 0 deletions doc/build/changelog/unreleased_20/7257.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@
long-documented approach of using ``Class.attrname`` for loader option
targets is now standard.

* Legacy forms of :func:`_sql.select` removed, including
``select([cols])``, the "whereclause" and keyword parameters of
``some_table.select()``.

* More are in progress as development continues
1 change: 0 additions & 1 deletion lib/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
from .sql import outparam
from .sql import over
from .sql import select
from .sql import subquery
from .sql import table
from .sql import tablesample
from .sql import text
Expand Down
2 changes: 1 addition & 1 deletion lib/sqlalchemy/future/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
from ..util.langhelpers import public_factory


select = public_factory(Select._create_future_select, ".future.select")
select = public_factory(Select._create, ".future.select")
1 change: 0 additions & 1 deletion lib/sqlalchemy/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
from .expression import Selectable
from .expression import StatementLambdaElement
from .expression import Subquery
from .expression import subquery
from .expression import table
from .expression import TableClause
from .expression import TableSample
Expand Down
25 changes: 21 additions & 4 deletions lib/sqlalchemy/sql/coercions.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,13 @@ def _literal_coercion(self, element, argname=None, type_=None, **kw):
class _SelectIsNotFrom:
__slots__ = ()

def _raise_for_expected(self, element, argname=None, resolved=None, **kw):
if isinstance(element, roles.SelectStatementRole) or isinstance(
resolved, roles.SelectStatementRole
def _raise_for_expected(
self, element, argname=None, resolved=None, advice=None, **kw
):
if (
not advice
and isinstance(element, roles.SelectStatementRole)
or isinstance(resolved, roles.SelectStatementRole)
):
advice = (
"To create a "
Expand All @@ -429,7 +433,7 @@ def _raise_for_expected(self, element, argname=None, resolved=None, **kw):
)
code = "89ve"
else:
advice = code = None
code = None

return super(_SelectIsNotFrom, self)._raise_for_expected(
element,
Expand Down Expand Up @@ -815,6 +819,19 @@ class ColumnsClauseImpl(_SelectIsNotFrom, _CoerceLiterals, RoleImpl):

_guess_straight_column = re.compile(r"^\w\S*$", re.I)

def _raise_for_expected(
self, element, argname=None, resolved=None, advice=None, **kw
):
if not advice and isinstance(element, list):
advice = (
f"Did you mean to say select("
f"{', '.join(repr(e) for e in element)})?"
)

return super(ColumnsClauseImpl, self)._raise_for_expected(
element, argname=argname, resolved=resolved, advice=advice, **kw
)

def _text_coercion(self, element, argname=None):
element = str(element)

Expand Down
5 changes: 0 additions & 5 deletions lib/sqlalchemy/sql/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

"""Defines the public namespace for SQL expression constructs.
Prior to version 0.9, this module contained all of "elements", "dml",
"default_comparator" and "selectable". The module was broken up
and most "factory" functions were moved to be grouped with their associated
class.
"""

Expand Down Expand Up @@ -169,7 +165,6 @@
from .selectable import Selectable
from .selectable import SelectBase
from .selectable import Subquery
from .selectable import subquery
from .selectable import TableClause
from .selectable import TableSample
from .selectable import TableValuedAlias
Expand Down
5 changes: 3 additions & 2 deletions lib/sqlalchemy/sql/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""SQL function API, factories, and built-in functions.
"""

from . import annotation
from . import coercions
from . import operators
Expand Down Expand Up @@ -557,7 +558,7 @@ def alias(self, name=None):
self, name, table_value_type=self.type
)

def select(self):
def select(self) -> "Select":
"""Produce a :func:`_expression.select` construct
against this :class:`.FunctionElement`.
Expand All @@ -566,7 +567,7 @@ def select(self):
s = select(function_element)
"""
s = Select._create_select(self)
s = Select._create(self)
if self._execution_options:
s = s.execution_options(**self._execution_options)
return s
Expand Down
Loading

0 comments on commit 54875c2

Please sign in to comment.