Skip to content

Commit 98eae4e

Browse files
committed
use code generation for scoped_session
our decorator thing generates code in any case, so point it at the file itself to generate real code for the blocks rather than doing things dynamically. this will allow typing tools to have no problem whatsoever and we also reduce import time overhead. file size will be a lot bigger though, shrugs. syntax / dupe method / etc. checking will be accomplished by our existing linting / typing / formatting tools. As we are also using "from __future__ import annotations", we also no longer have to apply quotes to generated annotations. Change-Id: I20962cb65bda63ff0fb67357ab346e9b1ef4f108
1 parent 15ef11e commit 98eae4e

File tree

13 files changed

+3936
-127
lines changed

13 files changed

+3936
-127
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
recursive-include doc *.html *.css *.txt *.js *.png *.py Makefile *.rst *.sty
55
recursive-include examples *.py *.xml
66
recursive-include test *.py *.dat *.testpatch
7+
recursive-include tools *.py
78

89
# for some reason in some environments stale Cython .c files
910
# are being pulled in, these should never be in a dist

lib/sqlalchemy/engine/base.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2672,14 +2672,18 @@ def get_execution_options(self) -> _ExecuteOptions:
26722672
@property
26732673
def name(self) -> str:
26742674
"""String name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
2675-
in use by this :class:`Engine`."""
2675+
in use by this :class:`Engine`.
2676+
2677+
"""
26762678

26772679
return self.dialect.name
26782680

26792681
@property
26802682
def driver(self) -> str:
26812683
"""Driver name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
2682-
in use by this :class:`Engine`."""
2684+
in use by this :class:`Engine`.
2685+
2686+
"""
26832687

26842688
return self.dialect.driver
26852689

lib/sqlalchemy/ext/asyncio/engine.py

+273-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
# This module is part of SQLAlchemy and is released under
66
# the MIT License: https://www.opensource.org/licenses/mit-license.php
7+
from __future__ import annotations
8+
9+
from typing import Any
10+
711
from . import exc as async_exc
812
from .base import ProxyComparable
913
from .base import StartableContext
@@ -72,7 +76,7 @@ class AsyncConnectable:
7276

7377
@util.create_proxy_methods(
7478
Connection,
75-
":class:`_future.Connection`",
79+
":class:`_engine.Connection`",
7680
":class:`_asyncio.AsyncConnection`",
7781
classmethods=[],
7882
methods=[],
@@ -125,6 +129,7 @@ def __init__(self, async_engine, sync_connection=None):
125129
.. seealso::
126130
127131
:ref:`asyncio_events`
132+
128133
"""
129134

130135
sync_engine: Engine
@@ -137,6 +142,7 @@ def __init__(self, async_engine, sync_connection=None):
137142
.. seealso::
138143
139144
:ref:`asyncio_events`
145+
140146
"""
141147

142148
@classmethod
@@ -552,10 +558,100 @@ def __await__(self):
552558
async def __aexit__(self, type_, value, traceback):
553559
await self.close()
554560

561+
# START PROXY METHODS AsyncConnection
562+
563+
# code within this block is **programmatically,
564+
# statically generated** by tools/generate_proxy_methods.py
565+
566+
@property
567+
def closed(self) -> Any:
568+
r"""Return True if this connection is closed.
569+
570+
.. container:: class_bases
571+
572+
Proxied for the :class:`_engine.Connection` class
573+
on behalf of the :class:`_asyncio.AsyncConnection` class.
574+
575+
""" # noqa: E501
576+
577+
return self._proxied.closed
578+
579+
@property
580+
def invalidated(self) -> Any:
581+
r"""Return True if this connection was invalidated.
582+
583+
.. container:: class_bases
584+
585+
Proxied for the :class:`_engine.Connection` class
586+
on behalf of the :class:`_asyncio.AsyncConnection` class.
587+
588+
This does not indicate whether or not the connection was
589+
invalidated at the pool level, however
590+
591+
592+
""" # noqa: E501
593+
594+
return self._proxied.invalidated
595+
596+
@property
597+
def dialect(self) -> Any:
598+
r"""Proxy for the :attr:`_engine.Connection.dialect` attribute
599+
on behalf of the :class:`_asyncio.AsyncConnection` class.
600+
601+
""" # noqa: E501
602+
603+
return self._proxied.dialect
604+
605+
@dialect.setter
606+
def dialect(self, attr: Any) -> None:
607+
self._proxied.dialect = attr
608+
609+
@property
610+
def default_isolation_level(self) -> Any:
611+
r"""The default isolation level assigned to this
612+
:class:`_engine.Connection`.
613+
614+
.. container:: class_bases
615+
616+
Proxied for the :class:`_engine.Connection` class
617+
on behalf of the :class:`_asyncio.AsyncConnection` class.
618+
619+
This is the isolation level setting that the
620+
:class:`_engine.Connection`
621+
has when first procured via the :meth:`_engine.Engine.connect` method.
622+
This level stays in place until the
623+
:paramref:`.Connection.execution_options.isolation_level` is used
624+
to change the setting on a per-:class:`_engine.Connection` basis.
625+
626+
Unlike :meth:`_engine.Connection.get_isolation_level`,
627+
this attribute is set
628+
ahead of time from the first connection procured by the dialect,
629+
so SQL query is not invoked when this accessor is called.
630+
631+
.. versionadded:: 0.9.9
632+
633+
.. seealso::
634+
635+
:meth:`_engine.Connection.get_isolation_level`
636+
- view current level
637+
638+
:paramref:`_sa.create_engine.isolation_level`
639+
- set per :class:`_engine.Engine` isolation level
640+
641+
:paramref:`.Connection.execution_options.isolation_level`
642+
- set per :class:`_engine.Connection` isolation level
643+
644+
645+
""" # noqa: E501
646+
647+
return self._proxied.default_isolation_level
648+
649+
# END PROXY METHODS AsyncConnection
650+
555651

556652
@util.create_proxy_methods(
557653
Engine,
558-
":class:`_future.Engine`",
654+
":class:`_engine.Engine`",
559655
":class:`_asyncio.AsyncEngine`",
560656
classmethods=[],
561657
methods=[
@@ -701,6 +797,181 @@ async def dispose(self):
701797

702798
return await greenlet_spawn(self.sync_engine.dispose)
703799

800+
# START PROXY METHODS AsyncEngine
801+
802+
# code within this block is **programmatically,
803+
# statically generated** by tools/generate_proxy_methods.py
804+
805+
def clear_compiled_cache(self) -> None:
806+
r"""Clear the compiled cache associated with the dialect.
807+
808+
.. container:: class_bases
809+
810+
Proxied for the :class:`_engine.Engine` class on
811+
behalf of the :class:`_asyncio.AsyncEngine` class.
812+
813+
This applies **only** to the built-in cache that is established
814+
via the :paramref:`_engine.create_engine.query_cache_size` parameter.
815+
It will not impact any dictionary caches that were passed via the
816+
:paramref:`.Connection.execution_options.query_cache` parameter.
817+
818+
.. versionadded:: 1.4
819+
820+
821+
""" # noqa: E501
822+
823+
return self._proxied.clear_compiled_cache()
824+
825+
def update_execution_options(self, **opt: Any) -> None:
826+
r"""Update the default execution_options dictionary
827+
of this :class:`_engine.Engine`.
828+
829+
.. container:: class_bases
830+
831+
Proxied for the :class:`_engine.Engine` class on
832+
behalf of the :class:`_asyncio.AsyncEngine` class.
833+
834+
The given keys/values in \**opt are added to the
835+
default execution options that will be used for
836+
all connections. The initial contents of this dictionary
837+
can be sent via the ``execution_options`` parameter
838+
to :func:`_sa.create_engine`.
839+
840+
.. seealso::
841+
842+
:meth:`_engine.Connection.execution_options`
843+
844+
:meth:`_engine.Engine.execution_options`
845+
846+
847+
""" # noqa: E501
848+
849+
return self._proxied.update_execution_options(**opt)
850+
851+
def get_execution_options(self) -> _ExecuteOptions:
852+
r"""Get the non-SQL options which will take effect during execution.
853+
854+
.. container:: class_bases
855+
856+
Proxied for the :class:`_engine.Engine` class on
857+
behalf of the :class:`_asyncio.AsyncEngine` class.
858+
859+
.. versionadded: 1.3
860+
861+
.. seealso::
862+
863+
:meth:`_engine.Engine.execution_options`
864+
865+
""" # noqa: E501
866+
867+
return self._proxied.get_execution_options()
868+
869+
@property
870+
def url(self) -> URL:
871+
r"""Proxy for the :attr:`_engine.Engine.url` attribute
872+
on behalf of the :class:`_asyncio.AsyncEngine` class.
873+
874+
""" # noqa: E501
875+
876+
return self._proxied.url
877+
878+
@url.setter
879+
def url(self, attr: URL) -> None:
880+
self._proxied.url = attr
881+
882+
@property
883+
def pool(self) -> Pool:
884+
r"""Proxy for the :attr:`_engine.Engine.pool` attribute
885+
on behalf of the :class:`_asyncio.AsyncEngine` class.
886+
887+
""" # noqa: E501
888+
889+
return self._proxied.pool
890+
891+
@pool.setter
892+
def pool(self, attr: Pool) -> None:
893+
self._proxied.pool = attr
894+
895+
@property
896+
def dialect(self) -> Dialect:
897+
r"""Proxy for the :attr:`_engine.Engine.dialect` attribute
898+
on behalf of the :class:`_asyncio.AsyncEngine` class.
899+
900+
""" # noqa: E501
901+
902+
return self._proxied.dialect
903+
904+
@dialect.setter
905+
def dialect(self, attr: Dialect) -> None:
906+
self._proxied.dialect = attr
907+
908+
@property
909+
def engine(self) -> Any:
910+
r""".. container:: class_bases
911+
912+
Proxied for the :class:`_engine.Engine` class
913+
on behalf of the :class:`_asyncio.AsyncEngine` class.
914+
915+
916+
""" # noqa: E501
917+
918+
return self._proxied.engine
919+
920+
@property
921+
def name(self) -> Any:
922+
r"""String name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
923+
in use by this :class:`Engine`.
924+
925+
.. container:: class_bases
926+
927+
Proxied for the :class:`_engine.Engine` class
928+
on behalf of the :class:`_asyncio.AsyncEngine` class.
929+
930+
931+
""" # noqa: E501
932+
933+
return self._proxied.name
934+
935+
@property
936+
def driver(self) -> Any:
937+
r"""Driver name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
938+
in use by this :class:`Engine`.
939+
940+
.. container:: class_bases
941+
942+
Proxied for the :class:`_engine.Engine` class
943+
on behalf of the :class:`_asyncio.AsyncEngine` class.
944+
945+
946+
""" # noqa: E501
947+
948+
return self._proxied.driver
949+
950+
@property
951+
def echo(self) -> Any:
952+
r"""When ``True``, enable log output for this element.
953+
954+
.. container:: class_bases
955+
956+
Proxied for the :class:`_engine.Engine` class
957+
on behalf of the :class:`_asyncio.AsyncEngine` class.
958+
959+
This has the effect of setting the Python logging level for the namespace
960+
of this element's class and object reference. A value of boolean ``True``
961+
indicates that the loglevel ``logging.INFO`` will be set for the logger,
962+
whereas the string value ``debug`` will set the loglevel to
963+
``logging.DEBUG``.
964+
965+
""" # noqa: E501
966+
967+
return self._proxied.echo
968+
969+
@echo.setter
970+
def echo(self, attr: Any) -> None:
971+
self._proxied.echo = attr
972+
973+
# END PROXY METHODS AsyncEngine
974+
704975

705976
class AsyncTransaction(ProxyComparable, StartableContext):
706977
"""An asyncio proxy for a :class:`_engine.Transaction`."""

0 commit comments

Comments
 (0)