summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2022-11-03 20:52:21 +0100
committerFederico Caselli <cfederico87@gmail.com>2022-11-16 23:03:04 +0100
commit4eb4ceca36c7ce931ea65ac06d6ed08bf459fc66 (patch)
tree4970cff3f78489a4a0066cd27fd4bae682402957 /lib/sqlalchemy/engine
parent3fc6c40ea77c971d3067dab0fdf57a5b5313b69b (diff)
downloadsqlalchemy-4eb4ceca36c7ce931ea65ac06d6ed08bf459fc66.tar.gz
Try running pyupgrade on the code
command run is "pyupgrade --py37-plus --keep-runtime-typing --keep-percent-format <files...>" pyupgrade will change assert_ to assertTrue. That was reverted since assertTrue does not exists in sqlalchemy fixtures Change-Id: Ie1ed2675c7b11d893d78e028aad0d1576baebb55
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r--lib/sqlalchemy/engine/base.py2
-rw-r--r--lib/sqlalchemy/engine/create.py8
-rw-r--r--lib/sqlalchemy/engine/cursor.py16
-rw-r--r--lib/sqlalchemy/engine/default.py39
-rw-r--r--lib/sqlalchemy/engine/interfaces.py16
-rw-r--r--lib/sqlalchemy/engine/reflection.py18
-rw-r--r--lib/sqlalchemy/engine/result.py4
7 files changed, 43 insertions, 60 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index b2f6b29b7..b686de0d6 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -2854,7 +2854,7 @@ class TwoPhaseTransaction(RootTransaction):
def __init__(self, connection: Connection, xid: Any):
self._is_prepared = False
self.xid = xid
- super(TwoPhaseTransaction, self).__init__(connection)
+ super().__init__(connection)
def prepare(self) -> None:
"""Prepare this :class:`.TwoPhaseTransaction`.
diff --git a/lib/sqlalchemy/engine/create.py b/lib/sqlalchemy/engine/create.py
index 1ad8c90e7..c8736392f 100644
--- a/lib/sqlalchemy/engine/create.py
+++ b/lib/sqlalchemy/engine/create.py
@@ -115,7 +115,7 @@ def create_engine(url: Union[str, URL], **kwargs: Any) -> Engine:
"is deprecated and will be removed in a future release. ",
),
)
-def create_engine(url: Union[str, "_url.URL"], **kwargs: Any) -> Engine:
+def create_engine(url: Union[str, _url.URL], **kwargs: Any) -> Engine:
"""Create a new :class:`_engine.Engine` instance.
The standard calling form is to send the :ref:`URL <database_urls>` as the
@@ -806,11 +806,11 @@ def engine_from_config(
"""
- options = dict(
- (key[len(prefix) :], configuration[key])
+ options = {
+ key[len(prefix) :]: configuration[key]
for key in configuration
if key.startswith(prefix)
- )
+ }
options["_coerce_config"] = True
options.update(kwargs)
url = options.pop("url")
diff --git a/lib/sqlalchemy/engine/cursor.py b/lib/sqlalchemy/engine/cursor.py
index f22e89fbe..33ee7866c 100644
--- a/lib/sqlalchemy/engine/cursor.py
+++ b/lib/sqlalchemy/engine/cursor.py
@@ -1230,15 +1230,11 @@ class BufferedRowCursorFetchStrategy(CursorFetchStrategy):
def soft_close(self, result, dbapi_cursor):
self._rowbuffer.clear()
- super(BufferedRowCursorFetchStrategy, self).soft_close(
- result, dbapi_cursor
- )
+ super().soft_close(result, dbapi_cursor)
def hard_close(self, result, dbapi_cursor):
self._rowbuffer.clear()
- super(BufferedRowCursorFetchStrategy, self).hard_close(
- result, dbapi_cursor
- )
+ super().hard_close(result, dbapi_cursor)
def fetchone(self, result, dbapi_cursor, hard_close=False):
if not self._rowbuffer:
@@ -1307,15 +1303,11 @@ class FullyBufferedCursorFetchStrategy(CursorFetchStrategy):
def soft_close(self, result, dbapi_cursor):
self._rowbuffer.clear()
- super(FullyBufferedCursorFetchStrategy, self).soft_close(
- result, dbapi_cursor
- )
+ super().soft_close(result, dbapi_cursor)
def hard_close(self, result, dbapi_cursor):
self._rowbuffer.clear()
- super(FullyBufferedCursorFetchStrategy, self).hard_close(
- result, dbapi_cursor
- )
+ super().hard_close(result, dbapi_cursor)
def fetchone(self, result, dbapi_cursor, hard_close=False):
if self._rowbuffer:
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index e5d613dd5..3cc9cab8b 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -200,9 +200,7 @@ class DefaultDialect(Dialect):
supports_sane_rowcount = True
supports_sane_multi_rowcount = True
- colspecs: MutableMapping[
- Type["TypeEngine[Any]"], Type["TypeEngine[Any]"]
- ] = {}
+ colspecs: MutableMapping[Type[TypeEngine[Any]], Type[TypeEngine[Any]]] = {}
default_paramstyle = "named"
supports_default_values = False
@@ -1486,21 +1484,17 @@ class DefaultExecutionContext(ExecutionContext):
use_server_side = self.execution_options.get(
"stream_results", True
) and (
- (
- self.compiled
- and isinstance(
- self.compiled.statement, expression.Selectable
- )
- or (
- (
- not self.compiled
- or isinstance(
- self.compiled.statement, expression.TextClause
- )
+ self.compiled
+ and isinstance(self.compiled.statement, expression.Selectable)
+ or (
+ (
+ not self.compiled
+ or isinstance(
+ self.compiled.statement, expression.TextClause
)
- and self.unicode_statement
- and SERVER_SIDE_CURSOR_RE.match(self.unicode_statement)
)
+ and self.unicode_statement
+ and SERVER_SIDE_CURSOR_RE.match(self.unicode_statement)
)
)
else:
@@ -1938,15 +1932,12 @@ class DefaultExecutionContext(ExecutionContext):
]
)
else:
- parameters = dict(
- (
- key,
- processors[key](compiled_params[key]) # type: ignore
- if key in processors
- else compiled_params[key],
- )
+ parameters = {
+ key: processors[key](compiled_params[key]) # type: ignore
+ if key in processors
+ else compiled_params[key]
for key in compiled_params
- )
+ }
return self._execute_scalar(
str(compiled), type_, parameters=parameters
)
diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py
index e10fab831..2f5efce25 100644
--- a/lib/sqlalchemy/engine/interfaces.py
+++ b/lib/sqlalchemy/engine/interfaces.py
@@ -757,7 +757,7 @@ class Dialect(EventTarget):
# create_engine() -> isolation_level currently goes here
_on_connect_isolation_level: Optional[IsolationLevel]
- execution_ctx_cls: Type["ExecutionContext"]
+ execution_ctx_cls: Type[ExecutionContext]
"""a :class:`.ExecutionContext` class used to handle statement execution"""
execute_sequence_format: Union[
@@ -963,7 +963,7 @@ class Dialect(EventTarget):
"""target database, when given a CTE with an INSERT statement, needs
the CTE to be below the INSERT"""
- colspecs: MutableMapping[Type["TypeEngine[Any]"], Type["TypeEngine[Any]"]]
+ colspecs: MutableMapping[Type[TypeEngine[Any]], Type[TypeEngine[Any]]]
"""A dictionary of TypeEngine classes from sqlalchemy.types mapped
to subclasses that are specific to the dialect class. This
dictionary is class-level only and is not accessed from the
@@ -1160,12 +1160,12 @@ class Dialect(EventTarget):
_bind_typing_render_casts: bool
- _type_memos: MutableMapping[TypeEngine[Any], "_TypeMemoDict"]
+ _type_memos: MutableMapping[TypeEngine[Any], _TypeMemoDict]
def _builtin_onconnect(self) -> Optional[_ListenerFnType]:
raise NotImplementedError()
- def create_connect_args(self, url: "URL") -> ConnectArgsType:
+ def create_connect_args(self, url: URL) -> ConnectArgsType:
"""Build DB-API compatible connection arguments.
Given a :class:`.URL` object, returns a tuple
@@ -1217,7 +1217,7 @@ class Dialect(EventTarget):
raise NotImplementedError()
@classmethod
- def type_descriptor(cls, typeobj: "TypeEngine[_T]") -> "TypeEngine[_T]":
+ def type_descriptor(cls, typeobj: TypeEngine[_T]) -> TypeEngine[_T]:
"""Transform a generic type to a dialect-specific type.
Dialect classes will usually use the
@@ -2155,7 +2155,7 @@ class Dialect(EventTarget):
self,
cursor: DBAPICursor,
statement: str,
- context: Optional["ExecutionContext"] = None,
+ context: Optional[ExecutionContext] = None,
) -> None:
"""Provide an implementation of ``cursor.execute(statement)``.
@@ -2210,7 +2210,7 @@ class Dialect(EventTarget):
"""
raise NotImplementedError()
- def on_connect_url(self, url: "URL") -> Optional[Callable[[Any], Any]]:
+ def on_connect_url(self, url: URL) -> Optional[Callable[[Any], Any]]:
"""return a callable which sets up a newly created DBAPI connection.
This method is a new hook that supersedes the
@@ -2556,7 +2556,7 @@ class Dialect(EventTarget):
"""
@classmethod
- def engine_created(cls, engine: "Engine") -> None:
+ def engine_created(cls, engine: Engine) -> None:
"""A convenience hook called before returning the final
:class:`_engine.Engine`.
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index f744d53ad..d1669cc3c 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -568,9 +568,9 @@ class Inspector(inspection.Inspectable["Inspector"]):
schema_fkeys = self.get_multi_foreign_keys(schname, **kw)
tnames.extend(schema_fkeys)
for (_, tname), fkeys in schema_fkeys.items():
- fknames_for_table[(schname, tname)] = set(
- [fk["name"] for fk in fkeys]
- )
+ fknames_for_table[(schname, tname)] = {
+ fk["name"] for fk in fkeys
+ }
for fkey in fkeys:
if (
tname != fkey["referred_table"]
@@ -1517,11 +1517,11 @@ class Inspector(inspection.Inspectable["Inspector"]):
# intended for reflection, e.g. oracle_resolve_synonyms.
# these are unconditionally passed to related Table
# objects
- reflection_options = dict(
- (k, table.dialect_kwargs.get(k))
+ reflection_options = {
+ k: table.dialect_kwargs.get(k)
for k in dialect.reflection_options
if k in table.dialect_kwargs
- )
+ }
table_key = (schema, table_name)
if _reflect_info is None or table_key not in _reflect_info.columns:
@@ -1644,8 +1644,8 @@ class Inspector(inspection.Inspectable["Inspector"]):
coltype = col_d["type"]
- col_kw = dict(
- (k, col_d[k]) # type: ignore[literal-required]
+ col_kw = {
+ k: col_d[k] # type: ignore[literal-required]
for k in [
"nullable",
"autoincrement",
@@ -1655,7 +1655,7 @@ class Inspector(inspection.Inspectable["Inspector"]):
"comment",
]
if k in col_d
- )
+ }
if "dialect_options" in col_d:
col_kw.update(col_d["dialect_options"])
diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index bcd2f0ea9..392cefa02 100644
--- a/lib/sqlalchemy/engine/result.py
+++ b/lib/sqlalchemy/engine/result.py
@@ -2342,7 +2342,7 @@ class ChunkedIteratorResult(IteratorResult[_TP]):
return self
def _soft_close(self, hard: bool = False, **kw: Any) -> None:
- super(ChunkedIteratorResult, self)._soft_close(hard=hard, **kw)
+ super()._soft_close(hard=hard, **kw)
self.chunks = lambda size: [] # type: ignore
def _fetchmany_impl(
@@ -2370,7 +2370,7 @@ class MergedResult(IteratorResult[_TP]):
self, cursor_metadata: ResultMetaData, results: Sequence[Result[_TP]]
):
self._results = results
- super(MergedResult, self).__init__(
+ super().__init__(
cursor_metadata,
itertools.chain.from_iterable(
r._raw_row_iterator() for r in results