From fa6dd376bb24845724287d980a98ea50eb1cfab1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 11 Jan 2017 10:12:12 -0500 Subject: Support python3.6 Corrects some warnings and adds tox config. Adds DeprecationWarning to the error category. Large sweep for string literals w/ backslashes as this is common in docstrings Co-authored-by: Andrii Soldatenko Fixes: #3886 Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337 --- lib/sqlalchemy/orm/__init__.py | 4 +- lib/sqlalchemy/orm/attributes.py | 2 +- lib/sqlalchemy/orm/descriptor_props.py | 2 +- lib/sqlalchemy/orm/events.py | 4 +- lib/sqlalchemy/orm/interfaces.py | 16 +-- lib/sqlalchemy/orm/mapper.py | 6 +- lib/sqlalchemy/orm/properties.py | 2 +- lib/sqlalchemy/orm/query.py | 184 ++++++++++++++++----------------- lib/sqlalchemy/orm/scoping.py | 2 +- lib/sqlalchemy/orm/session.py | 11 +- lib/sqlalchemy/orm/strategy_options.py | 14 +-- lib/sqlalchemy/orm/util.py | 18 ++-- 12 files changed, 133 insertions(+), 132 deletions(-) (limited to 'lib/sqlalchemy/orm') diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py index 22391e1de..449173548 100644 --- a/lib/sqlalchemy/orm/__init__.py +++ b/lib/sqlalchemy/orm/__init__.py @@ -71,7 +71,7 @@ from . import strategies as _strategies def create_session(bind=None, **kwargs): - """Create a new :class:`.Session` + r"""Create a new :class:`.Session` with no automation enabled by default. This function is used primarily for testing. The usual @@ -159,7 +159,7 @@ def backref(name, **kwargs): def deferred(*columns, **kw): - """Indicate a column-based mapped attribute that by default will + r"""Indicate a column-based mapped attribute that by default will not load unless accessed. :param \*columns: columns to be mapped. This is typically a single diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index ba14e561a..fc81db782 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -382,7 +382,7 @@ class AttributeImpl(object): parent_token=None, expire_missing=True, send_modified_events=True, **kwargs): - """Construct an AttributeImpl. + r"""Construct an AttributeImpl. \class_ associated class diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index 4949169ee..0792ff2e2 100644 --- a/lib/sqlalchemy/orm/descriptor_props.py +++ b/lib/sqlalchemy/orm/descriptor_props.py @@ -91,7 +91,7 @@ class CompositeProperty(DescriptorProperty): """ def __init__(self, class_, *attrs, **kwargs): - """Return a composite column-based property for use with a Mapper. + r"""Return a composite column-based property for use with a Mapper. See the mapping documentation section :ref:`mapper_composite` for a full usage example. diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index 406efb01f..653f66dd8 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -632,7 +632,7 @@ class MapperEvents(event.Events): _MapperEventsHold._clear() def instrument_class(self, mapper, class_): - """Receive a class when the mapper is first constructed, + r"""Receive a class when the mapper is first constructed, before instrumentation is applied to the mapped class. This event is the earliest phase of mapper construction. @@ -655,7 +655,7 @@ class MapperEvents(event.Events): """ def mapper_configured(self, mapper, class_): - """Called when a specific mapper has completed its own configuration + r"""Called when a specific mapper has completed its own configuration within the scope of the :func:`.configure_mappers` call. The :meth:`.MapperEvents.mapper_configured` event is invoked diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index dbf8a1b5d..3fad83ef4 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -247,7 +247,7 @@ class MapperProperty(_MappedAttribute, InspectionAttr, util.MemoizedSlots): class PropComparator(operators.ColumnOperators): - """Defines SQL operators for :class:`.MapperProperty` objects. + r"""Defines SQL operators for :class:`.MapperProperty` objects. SQLAlchemy allows for operators to be redefined at both the Core and ORM level. :class:`.PropComparator` @@ -273,9 +273,9 @@ class PropComparator(operators.ColumnOperators): # definition of custom PropComparator subclasses - from sqlalchemy.orm.properties import \\ - ColumnProperty,\\ - CompositeProperty,\\ + from sqlalchemy.orm.properties import \ + ColumnProperty,\ + CompositeProperty,\ RelationshipProperty class MyColumnComparator(ColumnProperty.Comparator): @@ -387,14 +387,14 @@ class PropComparator(operators.ColumnOperators): return a.of_type(class_) def of_type(self, class_): - """Redefine this object in terms of a polymorphic subclass. + r"""Redefine this object in terms of a polymorphic subclass. Returns a new PropComparator from which further criterion can be evaluated. e.g.:: - query.join(Company.employees.of_type(Engineer)).\\ + query.join(Company.employees.of_type(Engineer)).\ filter(Engineer.name=='foo') :param \class_: a class or mapper indicating that criterion will be @@ -406,7 +406,7 @@ class PropComparator(operators.ColumnOperators): return self.operate(PropComparator.of_type_op, class_) def any(self, criterion=None, **kwargs): - """Return true if this collection contains any member that meets the + r"""Return true if this collection contains any member that meets the given criterion. The usual implementation of ``any()`` is @@ -424,7 +424,7 @@ class PropComparator(operators.ColumnOperators): return self.operate(PropComparator.any_op, criterion, **kwargs) def has(self, criterion=None, **kwargs): - """Return true if this element references a member which meets the + r"""Return true if this element references a member which meets the given criterion. The usual implementation of ``has()`` is diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 25c6174ea..f45b56ae7 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -118,7 +118,7 @@ class Mapper(InspectionAttr): legacy_is_orphan=False, _compiled_cache_size=100, ): - """Return a new :class:`~.Mapper` object. + r"""Return a new :class:`~.Mapper` object. This function is typically used behind the scenes via the Declarative extension. When using Declarative, @@ -698,7 +698,7 @@ class Mapper(InspectionAttr): @property def entity(self): - """Part of the inspection API. + r"""Part of the inspection API. Returns self.class\_. @@ -2886,7 +2886,7 @@ def reconstructor(fn): def validates(*names, **kw): - """Decorate a method as a 'validator' for one or more named properties. + r"""Decorate a method as a 'validator' for one or more named properties. Designates a method as a validator, a method which receives the name of the attribute as well as a value to be assigned, or in the diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index a947ff435..63e7e1e20 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -42,7 +42,7 @@ class ColumnProperty(StrategizedProperty): '_mapped_by_synonym', '_deferred_column_loader') def __init__(self, *columns, **kwargs): - """Provide a column-level property for use with a Mapper. + r"""Provide a column-level property for use with a Mapper. Column-based properties can normally be applied to the mapper's ``properties`` dictionary using the :class:`.Column` element directly. diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 57e8a198c..a4c271ceb 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -473,7 +473,7 @@ class Query(object): return q.alias(name=name) def cte(self, name=None, recursive=False): - """Return the full SELECT statement represented by this + r"""Return the full SELECT statement represented by this :class:`.Query` represented as a common table expression (CTE). Parameters and usage are the same as those of the @@ -501,8 +501,8 @@ class Query(object): included_parts = session.query( Part.sub_part, Part.part, - Part.quantity).\\ - filter(Part.part=="our part").\\ + Part.quantity).\ + filter(Part.part=="our part").\ cte(name="included_parts", recursive=True) incl_alias = aliased(included_parts, name="pr") @@ -511,7 +511,7 @@ class Query(object): session.query( parts_alias.sub_part, parts_alias.part, - parts_alias.quantity).\\ + parts_alias.quantity).\ filter(parts_alias.part==incl_alias.c.sub_part) ) @@ -519,7 +519,7 @@ class Query(object): included_parts.c.sub_part, func.sum(included_parts.c.quantity). label('total_quantity') - ).\\ + ).\ group_by(included_parts.c.sub_part) .. seealso:: @@ -708,7 +708,7 @@ class Query(object): @_generative() def yield_per(self, count): - """Yield only ``count`` rows at a time. + r"""Yield only ``count`` rows at a time. The purpose of this method is when fetching very large result sets (> 10K rows), to batch results in sub-collections and yield them @@ -730,7 +730,7 @@ class Query(object): Or more selectively using :func:`.lazyload`; such as with an asterisk to specify the default loader scheme:: - q = sess.query(Object).yield_per(100).\\ + q = sess.query(Object).yield_per(100).\ options(lazyload('*'), joinedload(Object.some_related)) .. warning:: @@ -986,7 +986,7 @@ class Query(object): self.session = session def from_self(self, *entities): - """return a Query that selects from this Query's + r"""return a Query that selects from this Query's SELECT statement. :meth:`.Query.from_self` essentially turns the SELECT statement @@ -1013,8 +1013,8 @@ class Query(object): the set of user objects we query against, and then apply additional joins against that row-limited set:: - q = session.query(User).filter(User.name.like('e%')).\\ - limit(5).from_self().\\ + q = session.query(User).filter(User.name.like('e%')).\ + limit(5).from_self().\ join(User.addresses).filter(Address.email.like('q%')) The above query joins to the ``Address`` entity but only against the @@ -1039,9 +1039,9 @@ class Query(object): refer to the ``User`` entity without any additional aliasing applied to it, those references wil be in terms of the subquery:: - q = session.query(User).filter(User.name.like('e%')).\\ - limit(5).from_self().\\ - join(User.addresses).filter(Address.email.like('q%')).\\ + q = session.query(User).filter(User.name.like('e%')).\ + limit(5).from_self().\ + join(User.addresses).filter(Address.email.like('q%')).\ order_by(User.name) The ORDER BY against ``User.name`` is aliased to be in terms of the @@ -1074,8 +1074,8 @@ class Query(object): ``Address`` entity on the outside, but we only wanted the outer query to return the ``Address.email`` column:: - q = session.query(User).filter(User.name.like('e%')).\\ - limit(5).from_self(Address.email).\\ + q = session.query(User).filter(User.name.like('e%')).\ + limit(5).from_self(Address.email).\ join(User.addresses).filter(Address.email.like('q%')) yielding: @@ -1101,10 +1101,10 @@ class Query(object): then a subquery, and then we'd like :func:`.contains_eager` to access the ``User`` columns:: - q = session.query(Address).join(Address.user).\\ + q = session.query(Address).join(Address.user).\ filter(User.name.like('e%')) - q = q.add_entity(User).from_self().\\ + q = q.add_entity(User).from_self().\ options(contains_eager(Address.user)) We use :meth:`.Query.add_entity` above **before** we call @@ -1219,18 +1219,18 @@ class Query(object): # Users, filtered on some arbitrary criterion # and then ordered by related email address - q = session.query(User).\\ - join(User.address).\\ - filter(User.name.like('%ed%')).\\ + q = session.query(User).\ + join(User.address).\ + filter(User.name.like('%ed%')).\ order_by(Address.email) # given *only* User.id==5, Address.email, and 'q', what # would the *next* User in the result be ? - subq = q.with_entities(Address.email).\\ - order_by(None).\\ - filter(User.id==5).\\ + subq = q.with_entities(Address.email).\ + order_by(None).\ + filter(User.id==5).\ subquery() - q = q.join((subq, subq.c.email < Address.email)).\\ + q = q.join((subq, subq.c.email < Address.email)).\ limit(1) .. versionadded:: 0.6.5 @@ -1434,7 +1434,7 @@ class Query(object): @_generative() def params(self, *args, **kwargs): - """add values for bind parameters which may have been + r"""add values for bind parameters which may have been specified in filter(). parameters may be specified using \**kwargs, or optionally a single @@ -1454,7 +1454,7 @@ class Query(object): @_generative(_no_statement_condition, _no_limit_offset) def filter(self, *criterion): - """apply the given filtering criterion to a copy + r"""apply the given filtering criterion to a copy of this :class:`.Query`, using SQL expressions. e.g.:: @@ -1465,7 +1465,7 @@ class Query(object): is that they will be joined together using the :func:`.and_` function:: - session.query(MyClass).\\ + session.query(MyClass).\ filter(MyClass.name == 'some name', MyClass.id > 5) The criterion is any SQL expression object applicable to the @@ -1488,7 +1488,7 @@ class Query(object): self._criterion = criterion def filter_by(self, **kwargs): - """apply the given filtering criterion to a copy + r"""apply the given filtering criterion to a copy of this :class:`.Query`, using keyword expressions. e.g.:: @@ -1499,7 +1499,7 @@ class Query(object): is that they will be joined together using the :func:`.and_` function:: - session.query(MyClass).\\ + session.query(MyClass).\ filter_by(name = 'some name', id = 5) The keyword expressions are extracted from the primary @@ -1576,7 +1576,7 @@ class Query(object): @_generative(_no_statement_condition, _no_limit_offset) def having(self, criterion): - """apply a HAVING criterion to the query and return the + r"""apply a HAVING criterion to the query and return the newly resulting :class:`.Query`. :meth:`~.Query.having` is used in conjunction with @@ -1585,9 +1585,9 @@ class Query(object): HAVING criterion makes it possible to use filters on aggregate functions like COUNT, SUM, AVG, MAX, and MIN, eg.:: - q = session.query(User.id).\\ - join(User.addresses).\\ - group_by(User.id).\\ + q = session.query(User.id).\ + join(User.addresses).\ + group_by(User.id).\ having(func.count(Address.id) > 2) """ @@ -1697,7 +1697,7 @@ class Query(object): return self._set_op(expression.except_all, *q) def join(self, *props, **kwargs): - """Create a SQL JOIN against this :class:`.Query` object's criterion + r"""Create a SQL JOIN against this :class:`.Query` object's criterion and apply generatively, returning the newly resulting :class:`.Query`. **Simple Relationship Joins** @@ -1735,9 +1735,9 @@ class Query(object): :meth:`~.Query.join`, each using an explicit attribute to indicate the source entity:: - q = session.query(User).\\ - join(User.orders).\\ - join(Order.items).\\ + q = session.query(User).\ + join(User.orders).\ + join(Order.items).\ join(Item.keywords) **Joins to a Target Entity or Selectable** @@ -1772,10 +1772,10 @@ class Query(object): a_alias = aliased(Address) - q = session.query(User).\\ - join(User.addresses).\\ - join(a_alias, User.addresses).\\ - filter(Address.email_address=='ed@foo.com').\\ + q = session.query(User).\ + join(User.addresses).\ + join(a_alias, User.addresses).\ + filter(Address.email_address=='ed@foo.com').\ filter(a_alias.email_address=='ed@bar.com') Where above, the generated SQL would be similar to:: @@ -1813,11 +1813,11 @@ class Query(object): :func:`.alias` and :func:`.select` constructs, with either the one or two-argument forms:: - addresses_q = select([Address.user_id]).\\ - where(Address.email_address.endswith("@bar.com")).\\ + addresses_q = select([Address.user_id]).\ + where(Address.email_address.endswith("@bar.com")).\ alias() - q = session.query(User).\\ + q = session.query(User).\ join(addresses_q, addresses_q.c.user_id==User.id) :meth:`~.Query.join` also features the ability to *adapt* a @@ -1826,8 +1826,8 @@ class Query(object): against ``Address``, allowing the relationship denoted by ``User.addresses`` to *adapt* itself to the altered target:: - address_subq = session.query(Address).\\ - filter(Address.email_address == 'ed@foo.com').\\ + address_subq = session.query(Address).\ + filter(Address.email_address == 'ed@foo.com').\ subquery() q = session.query(User).join(address_subq, User.addresses) @@ -1846,7 +1846,7 @@ class Query(object): The above form allows one to fall back onto an explicit ON clause at any time:: - q = session.query(User).\\ + q = session.query(User).\ join(address_subq, User.id==address_subq.c.user_id) **Controlling what to Join From** @@ -1859,8 +1859,8 @@ class Query(object): the :class:`.Query` to select first from the ``User`` entity:: - q = session.query(Address).select_from(User).\\ - join(User.addresses).\\ + q = session.query(Address).select_from(User).\ + join(User.addresses).\ filter(User.name == 'ed') Which will produce SQL similar to:: @@ -1876,7 +1876,7 @@ class Query(object): when a query is being joined algorithmically, such as when querying self-referentially to an arbitrary depth:: - q = session.query(Node).\\ + q = session.query(Node).\ join("children", "children", aliased=True) When ``aliased=True`` is used, the actual "alias" construct @@ -1884,8 +1884,8 @@ class Query(object): :meth:`.Query.filter` will adapt the incoming entity to the last join point:: - q = session.query(Node).\\ - join("children", "children", aliased=True).\\ + q = session.query(Node).\ + join("children", "children", aliased=True).\ filter(Node.name == 'grandchild 1') When using automatic aliasing, the ``from_joinpoint=True`` @@ -1893,19 +1893,19 @@ class Query(object): multiple calls to :meth:`~.Query.join`, so that each path along the way can be further filtered:: - q = session.query(Node).\\ - join("children", aliased=True).\\ - filter(Node.name='child 1').\\ - join("children", aliased=True, from_joinpoint=True).\\ + q = session.query(Node).\ + join("children", aliased=True).\ + filter(Node.name='child 1').\ + join("children", aliased=True, from_joinpoint=True).\ filter(Node.name == 'grandchild 1') The filtering aliases above can then be reset back to the original ``Node`` entity using :meth:`~.Query.reset_joinpoint`:: - q = session.query(Node).\\ - join("children", "children", aliased=True).\\ - filter(Node.name == 'grandchild 1').\\ - reset_joinpoint().\\ + q = session.query(Node).\ + join("children", "children", aliased=True).\ + filter(Node.name == 'grandchild 1').\ + reset_joinpoint().\ filter(Node.name == 'parent 1) For an example of ``aliased=True``, see the distribution @@ -2329,7 +2329,7 @@ class Query(object): @_generative(_no_clauseelement_condition) def select_from(self, *from_obj): - """Set the FROM clause of this :class:`.Query` explicitly. + r"""Set the FROM clause of this :class:`.Query` explicitly. :meth:`.Query.select_from` is often used in conjunction with :meth:`.Query.join` in order to control which entity is selected @@ -2343,8 +2343,8 @@ class Query(object): A typical example:: - q = session.query(Address).select_from(User).\\ - join(User.addresses).\\ + q = session.query(Address).select_from(User).\ + join(User.addresses).\ filter(User.name == 'ed') Which produces SQL equivalent to:: @@ -2377,7 +2377,7 @@ class Query(object): @_generative(_no_clauseelement_condition) def select_entity_from(self, from_obj): - """Set the FROM clause of this :class:`.Query` to a + r"""Set the FROM clause of this :class:`.Query` to a core selectable, applying it as a replacement FROM clause for corresponding mapped entities. @@ -2398,8 +2398,8 @@ class Query(object): select_stmt = select([User]).where(User.id == 7) - q = session.query(User).\\ - select_entity_from(select_stmt).\\ + q = session.query(User).\ + select_entity_from(select_stmt).\ filter(User.name == 'ed') The query generated will select ``User`` entities directly @@ -2419,8 +2419,8 @@ class Query(object): version 0.9, does not affect existing entities. The statement below:: - q = session.query(User).\\ - select_from(select_stmt).\\ + q = session.query(User).\ + select_from(select_stmt).\ filter(User.name == 'ed') Produces SQL where both the ``user`` table as well as the @@ -2546,7 +2546,7 @@ class Query(object): @_generative(_no_statement_condition) def distinct(self, *criterion): - """Apply a ``DISTINCT`` to the query and return the newly resulting + r"""Apply a ``DISTINCT`` to the query and return the newly resulting ``Query``. @@ -2578,7 +2578,7 @@ class Query(object): @_generative() def prefix_with(self, *prefixes): - """Apply the prefixes to the query and return the newly resulting + r"""Apply the prefixes to the query and return the newly resulting ``Query``. :param \*prefixes: optional prefixes, typically strings, @@ -2586,8 +2586,8 @@ class Query(object): e.g.:: - query = sess.query(User.name).\\ - prefix_with('HIGH_PRIORITY').\\ + query = sess.query(User.name).\ + prefix_with('HIGH_PRIORITY').\ prefix_with('SQL_SMALL_RESULT', 'ALL') Would render:: @@ -2609,7 +2609,7 @@ class Query(object): @_generative() def suffix_with(self, *suffixes): - """Apply the suffix to the query and return the newly resulting + r"""Apply the suffix to the query and return the newly resulting ``Query``. :param \*suffixes: optional suffixes, typically strings, @@ -2984,7 +2984,7 @@ class Query(object): statement.with_only_columns([1])) def count(self): - """Return a count of rows this Query would return. + r"""Return a count of rows this Query would return. This generates the SQL for this Query as follows:: @@ -3011,7 +3011,7 @@ class Query(object): # return count of user "id" grouped # by "name" - session.query(func.count(User.id)).\\ + session.query(func.count(User.id)).\ group_by(User.name) from sqlalchemy import distinct @@ -3024,16 +3024,16 @@ class Query(object): return self.from_self(col).scalar() def delete(self, synchronize_session='evaluate'): - """Perform a bulk delete query. + r"""Perform a bulk delete query. Deletes rows matched by this query from the database. E.g.:: - sess.query(User).filter(User.age == 25).\\ + sess.query(User).filter(User.age == 25).\ delete(synchronize_session=False) - sess.query(User).filter(User.age == 25).\\ + sess.query(User).filter(User.age == 25).\ delete(synchronize_session='evaluate') .. warning:: The :meth:`.Query.delete` method is a "bulk" operation, @@ -3081,9 +3081,9 @@ class Query(object): subclasses ``Employee``, a DELETE against the ``Employee`` table would look like:: - session.query(Engineer).\\ - filter(Engineer.id == Employee.id).\\ - filter(Employee.name == 'dilbert').\\ + session.query(Engineer).\ + filter(Engineer.id == Employee.id).\ + filter(Employee.name == 'dilbert').\ delete() However the above SQL will not delete from the Engineer table, @@ -3149,16 +3149,16 @@ class Query(object): return delete_op.rowcount def update(self, values, synchronize_session='evaluate', update_args=None): - """Perform a bulk update query. + r"""Perform a bulk update query. Updates rows matched by this query in the database. E.g.:: - sess.query(User).filter(User.age == 25).\\ + sess.query(User).filter(User.age == 25).\ update({User.age: User.age - 10}, synchronize_session=False) - sess.query(User).filter(User.age == 25).\\ + sess.query(User).filter(User.age == 25).\ update({"age": User.age - 10}, synchronize_session='evaluate') @@ -3251,9 +3251,9 @@ class Query(object): local table using criteria against the ``Employee`` local table might look like:: - session.query(Engineer).\\ - filter(Engineer.id == Employee.id).\\ - filter(Employee.name == 'dilbert').\\ + session.query(Engineer).\ + filter(Engineer.id == Employee.id).\ + filter(Employee.name == 'dilbert').\ update({"engineer_type": "programmer"}) * The polymorphic identity WHERE criteria is **not** included @@ -3697,7 +3697,7 @@ class Bundle(InspectionAttr): is_aliased_class = False def __init__(self, name, *exprs, **kw): - """Construct a new :class:`.Bundle`. + r"""Construct a new :class:`.Bundle`. e.g.:: @@ -4081,7 +4081,7 @@ class QueryContext(object): class AliasOption(interfaces.MapperOption): def __init__(self, alias): - """Return a :class:`.MapperOption` that will indicate to the :class:`.Query` + r"""Return a :class:`.MapperOption` that will indicate to the :class:`.Query` that the main table has been aliased. This is a seldom-used option to suit the @@ -4090,12 +4090,12 @@ class AliasOption(interfaces.MapperOption): statement that aliases the parent table. E.g.:: # define an aliased UNION called 'ulist' - ulist = users.select(users.c.user_id==7).\\ - union(users.select(users.c.user_id>7)).\\ + ulist = users.select(users.c.user_id==7).\ + union(users.select(users.c.user_id>7)).\ alias('ulist') # add on an eager load of "addresses" - statement = ulist.outerjoin(addresses).\\ + statement = ulist.outerjoin(addresses).\ select().apply_labels() # create query, indicating "ulist" will be an diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py index f51dbc68c..05b881320 100644 --- a/lib/sqlalchemy/orm/scoping.py +++ b/lib/sqlalchemy/orm/scoping.py @@ -51,7 +51,7 @@ class scoped_session(object): self.registry = ThreadLocalRegistry(session_factory) def __call__(self, **kw): - """Return the current :class:`.Session`, creating it + r"""Return the current :class:`.Session`, creating it using the :attr:`.scoped_session.session_factory` if not present. :param \**kw: Keyword arguments will be passed to the diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 8a1dff163..081920487 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -592,7 +592,7 @@ class Session(_SessionClassMethods): weak_identity_map=True, binds=None, extension=None, info=None, query_cls=query.Query): - """Construct a new Session. + r"""Construct a new Session. See also the :class:`.sessionmaker` function which is used to generate a :class:`.Session`-producing callable with a given @@ -897,7 +897,7 @@ class Session(_SessionClassMethods): close_with_result=False, execution_options=None, **kw): - """Return a :class:`.Connection` object corresponding to this + r"""Return a :class:`.Connection` object corresponding to this :class:`.Session` object's transactional state. If this :class:`.Session` is configured with ``autocommit=False``, @@ -976,7 +976,7 @@ class Session(_SessionClassMethods): return conn def execute(self, clause, params=None, mapper=None, bind=None, **kw): - """Execute a SQL expression construct or string statement within + r"""Execute a SQL expression construct or string statement within the current transaction. Returns a :class:`.ResultProxy` representing @@ -2507,7 +2507,7 @@ class Session(_SessionClassMethods): def is_modified(self, instance, include_collections=True, passive=True): - """Return ``True`` if the given instance has locally + r"""Return ``True`` if the given instance has locally modified attributes. This method retrieves the history for each instrumented @@ -2565,6 +2565,7 @@ class Session(_SessionClassMethods): or many-to-one foreign keys) that would result in an UPDATE for this instance upon flush. :param passive: + .. versionchanged:: 0.8 Ignored for backwards compatibility. When using SQLAlchemy 0.7 and earlier, this flag should always @@ -2769,7 +2770,7 @@ class sessionmaker(_SessionClassMethods): autocommit=False, expire_on_commit=True, info=None, **kw): - """Construct a new :class:`.sessionmaker`. + r"""Construct a new :class:`.sessionmaker`. All arguments here except for ``class_`` correspond to arguments accepted by :class:`.Session` directly. See the diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index 2f98dc72a..bae2b73e2 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -552,7 +552,7 @@ See :func:`.orm.%(name)s` for usage examples. @loader_option() def contains_eager(loadopt, attr, alias=None): - """Indicate that the given attribute should be eagerly loaded from + r"""Indicate that the given attribute should be eagerly loaded from columns stated manually in the query. This function is part of the :class:`.Load` interface and supports @@ -561,8 +561,8 @@ def contains_eager(loadopt, attr, alias=None): The option is used in conjunction with an explicit join that loads the desired rows, i.e.:: - sess.query(Order).\\ - join(Order.user).\\ + sess.query(Order).\ + join(Order.user).\ options(contains_eager(Order.user)) The above query would join from the ``Order`` entity to its related @@ -575,8 +575,8 @@ def contains_eager(loadopt, attr, alias=None): the eagerly-loaded rows are to come from an aliased table:: user_alias = aliased(User) - sess.query(Order).\\ - join((user_alias, Order.user)).\\ + sess.query(Order).\ + join((user_alias, Order.user)).\ options(contains_eager(Order.user, alias=user_alias)) .. seealso:: @@ -953,7 +953,7 @@ def defaultload(*keys): @loader_option() def defer(loadopt, key): - """Indicate that the given column-oriented attribute should be deferred, e.g. + r"""Indicate that the given column-oriented attribute should be deferred, e.g. not loaded until accessed. This function is part of the :class:`.Load` interface and supports @@ -1017,7 +1017,7 @@ def defer(key, *addl_attrs): @loader_option() def undefer(loadopt, key): - """Indicate that the given column-oriented attribute should be undeferred, + r"""Indicate that the given column-oriented attribute should be undeferred, e.g. specified within the SELECT statement of the entity as a whole. The column being undeferred is typically set up on the mapping as a diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index d0fc12fe1..b4d5b8a9e 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -72,7 +72,7 @@ class CascadeOptions(frozenset): def from_string(cls, arg): values = [ c for c - in re.split('\s*,\s*', arg or "") + in re.split(r'\s*,\s*', arg or "") if c ] return cls(values) @@ -309,7 +309,7 @@ class ORMAdapter(sql_util.ColumnAdapter): class AliasedClass(object): - """Represents an "aliased" form of a mapped class for usage with Query. + r"""Represents an "aliased" form of a mapped class for usage with Query. The ORM equivalent of a :func:`sqlalchemy.sql.expression.alias` construct, this object mimics the mapped class using a @@ -323,8 +323,8 @@ class AliasedClass(object): # find all pairs of users with the same name user_alias = aliased(User) - session.query(User, user_alias).\\ - join((user_alias, User.id > user_alias.id)).\\ + session.query(User, user_alias).\ + join((user_alias, User.id > user_alias.id)).\ filter(User.name==user_alias.name) The resulting object is an instance of :class:`.AliasedClass`. @@ -888,7 +888,7 @@ class _ORMJoin(expression.Join): def join( left, right, onclause=None, isouter=False, full=False, join_to_left=None): - """Produce an inner join between left and right clauses. + r"""Produce an inner join between left and right clauses. :func:`.orm.join` is an extension to the core join interface provided by :func:`.sql.expression.join()`, where the @@ -907,15 +907,15 @@ def join( :meth:`.Query.select_from` method, as in:: from sqlalchemy.orm import join - session.query(User).\\ - select_from(join(User, Address, User.addresses)).\\ + session.query(User).\ + select_from(join(User, Address, User.addresses)).\ filter(Address.email_address=='foo@bar.com') In modern SQLAlchemy the above join can be written more succinctly as:: - session.query(User).\\ - join(User.addresses).\\ + session.query(User).\ + join(User.addresses).\ filter(Address.email_address=='foo@bar.com') See :meth:`.Query.join` for information on modern usage -- cgit v1.2.1