Fix type errors surfaced by mypy 1.16

Change-Id: I50bbd760577ff7c865c81153041e82bba068e5d8
This commit is contained in:
Federico Caselli
2025-05-30 22:53:59 +02:00
committed by Mike Bayer
parent c8e558b4f5
commit 68cd3e8ec7
33 changed files with 78 additions and 72 deletions
+1 -1
View File
@@ -166,7 +166,7 @@ class MySQLDialect_aiomysql(MySQLDialect_pymysql):
driver = "aiomysql"
supports_statement_cache = True
supports_server_side_cursors = True # type: ignore[assignment]
supports_server_side_cursors = True
_sscursor = AsyncAdapt_aiomysql_ss_cursor
is_async = True
+1 -1
View File
@@ -153,7 +153,7 @@ class MySQLDialect_asyncmy(MySQLDialect_pymysql):
driver = "asyncmy"
supports_statement_cache = True
supports_server_side_cursors = True # type: ignore[assignment]
supports_server_side_cursors = True
_sscursor = AsyncAdapt_asyncmy_ss_cursor
is_async = True
@@ -117,13 +117,13 @@ class IdentifierPreparerCommon_mysqlconnector:
return value
class MySQLIdentifierPreparer_mysqlconnector( # type:ignore[misc]
class MySQLIdentifierPreparer_mysqlconnector(
IdentifierPreparerCommon_mysqlconnector, MySQLIdentifierPreparer
):
pass
class MariaDBIdentifierPreparer_mysqlconnector( # type:ignore[misc]
class MariaDBIdentifierPreparer_mysqlconnector(
IdentifierPreparerCommon_mysqlconnector, MariaDBIdentifierPreparer
):
pass
+1 -1
View File
@@ -152,7 +152,7 @@ class MySQLDialect_mysqldb(MySQLDialect):
return (0, 0, 0)
@util.langhelpers.memoized_property
def supports_server_side_cursors(self) -> bool: # type: ignore[override]
def supports_server_side_cursors(self) -> bool:
try:
cursors = __import__("MySQLdb.cursors").cursors
self._sscursor = cursors.SSCursor
+2 -2
View File
@@ -75,7 +75,7 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb):
description_encoding = None
@langhelpers.memoized_property
def supports_server_side_cursors(self) -> bool: # type: ignore[override]
def supports_server_side_cursors(self) -> bool:
try:
cursors = __import__("pymysql.cursors").cursors
self._sscursor = cursors.SSCursor
@@ -115,7 +115,7 @@ class MySQLDialect_pymysql(MySQLDialect_mysqldb):
not insp.defaults or insp.defaults[0] is not False
)
def do_ping(self, dbapi_connection: DBAPIConnection) -> Literal[True]: # type: ignore # noqa: E501
def do_ping(self, dbapi_connection: DBAPIConnection) -> Literal[True]:
if self._send_false_to_ping:
dbapi_connection.ping(False)
else:
+1 -1
View File
@@ -396,7 +396,7 @@ class ARRAY(sqltypes.ARRAY[_T]):
def _against_native_enum(self) -> bool:
return (
isinstance(self.item_type, sqltypes.Enum)
and self.item_type.native_enum # type: ignore[attr-defined]
and self.item_type.native_enum
)
def literal_processor(
+2 -2
View File
@@ -271,9 +271,9 @@ class Range(Generic[_T]):
value2 += step
value2_inc = False
if value1 < value2: # type: ignore
if value1 < value2:
return -1
elif value1 > value2: # type: ignore
elif value1 > value2:
return 1
elif only_values:
return 0
+1 -1
View File
@@ -26,7 +26,7 @@ except ModuleNotFoundError:
def _is_compiled() -> bool:
"""Utility function to indicate if this module is compiled or not."""
return cython.compiled # type: ignore[no-any-return]
return cython.compiled # type: ignore[no-any-return,unused-ignore]
# END GENERATED CYTHON IMPORT
+1 -1
View File
@@ -35,7 +35,7 @@ except ModuleNotFoundError:
def _is_compiled() -> bool:
"""Utility function to indicate if this module is compiled or not."""
return cython.compiled # type: ignore[no-any-return]
return cython.compiled # type: ignore[no-any-return,unused-ignore]
# END GENERATED CYTHON IMPORT
+1 -1
View File
@@ -37,7 +37,7 @@ except ModuleNotFoundError:
def _is_compiled() -> bool:
"""Utility function to indicate if this module is compiled or not."""
return cython.compiled # type: ignore[no-any-return]
return cython.compiled # type: ignore[no-any-return,unused-ignore]
# END GENERATED CYTHON IMPORT
+3 -3
View File
@@ -1448,15 +1448,15 @@ class _NoResultMetaData(ResultMetaData):
self._we_dont_return_rows()
@property
def _keymap(self):
def _keymap(self): # type: ignore[override]
self._we_dont_return_rows()
@property
def _key_to_index(self):
def _key_to_index(self): # type: ignore[override]
self._we_dont_return_rows()
@property
def _processors(self):
def _processors(self): # type: ignore[override]
self._we_dont_return_rows()
@property
+3 -2
View File
@@ -481,7 +481,7 @@ class DefaultDialect(Dialect):
return weakref.WeakKeyDictionary()
@property
def dialect_description(self):
def dialect_description(self): # type: ignore[override]
return self.name + "+" + self.driver
@property
@@ -1632,7 +1632,7 @@ class DefaultExecutionContext(ExecutionContext):
return "unknown"
@property
def executemany(self):
def executemany(self): # type: ignore[override]
return self.execute_style in (
ExecuteStyle.EXECUTEMANY,
ExecuteStyle.INSERTMANYVALUES,
@@ -1846,6 +1846,7 @@ class DefaultExecutionContext(ExecutionContext):
if self._rowcount is None and exec_opt.get("preserve_rowcount", False):
self._rowcount = self.cursor.rowcount
yp: Optional[Union[int, bool]]
if self.is_crud or self.is_text:
result = self._setup_dml_or_text_result()
yp = False
+1
View File
@@ -524,6 +524,7 @@ class MutableBase:
if val is not None:
if coerce:
val = cls.coerce(key, val)
assert val is not None
state.dict[key] = val
val._parents[state] = key
+2 -2
View File
@@ -631,11 +631,11 @@ def _create_proxied_attribute(
self._doc = self.__doc__ = doc
@property
def _parententity(self):
def _parententity(self): # type: ignore[override]
return inspection.inspect(self.class_, raiseerr=False)
@property
def parent(self):
def parent(self): # type: ignore[override]
return inspection.inspect(self.class_, raiseerr=False)
_is_internal_proxy = True
+1 -2
View File
@@ -1998,8 +1998,7 @@ class _DeferredMapperConfig(_ClassScanMapperConfig):
def _early_mapping(self, mapper_kw: _MapperKwArgs) -> None:
pass
# mypy disallows plain property override of variable
@property # type: ignore
@property
def cls(self) -> Type[Any]:
return self._cls() # type: ignore
+12 -8
View File
@@ -1032,7 +1032,7 @@ class Mapper(
"""
primary_key: Tuple[Column[Any], ...]
primary_key: Tuple[ColumnElement[Any], ...]
"""An iterable containing the collection of :class:`_schema.Column`
objects
which comprise the 'primary key' of the mapped table, from the
@@ -2487,7 +2487,7 @@ class Mapper(
if spec == "*":
mappers = list(self.self_and_descendants)
elif spec:
mapper_set = set()
mapper_set: Set[Mapper[Any]] = set()
for m in util.to_list(spec):
m = _class_to_mapper(m)
if not m.isa(self):
@@ -3371,9 +3371,11 @@ class Mapper(
return self.class_manager.mapper.base_mapper
def _result_has_identity_key(self, result, adapter=None):
pk_cols: Sequence[ColumnClause[Any]] = self.primary_key
if adapter:
pk_cols = [adapter.columns[c] for c in pk_cols]
pk_cols: Sequence[ColumnElement[Any]]
if adapter is not None:
pk_cols = [adapter.columns[c] for c in self.primary_key]
else:
pk_cols = self.primary_key
rk = result.keys()
for col in pk_cols:
if col not in rk:
@@ -3398,9 +3400,11 @@ class Mapper(
for the "row" argument
"""
pk_cols: Sequence[ColumnClause[Any]] = self.primary_key
if adapter:
pk_cols = [adapter.columns[c] for c in pk_cols]
pk_cols: Sequence[ColumnElement[Any]]
if adapter is not None:
pk_cols = [adapter.columns[c] for c in self.primary_key]
else:
pk_cols = self.primary_key
mapping: RowMapping
if hasattr(row, "_mapping"):
+1 -1
View File
@@ -239,7 +239,7 @@ class ColumnProperty(
return self.strategy._have_default_expression # type: ignore
return ("deferred", True) not in self.strategy_key or (
self not in self.parent._readonly_props # type: ignore
self not in self.parent._readonly_props
)
@util.preload_module("sqlalchemy.orm.state", "sqlalchemy.orm.strategies")
+1 -2
View File
@@ -533,8 +533,7 @@ class RelationshipProperty(
else:
self._overlaps = ()
# mypy ignoring the @property setter
self.cascade = cascade # type: ignore
self.cascade = cascade
if back_populates:
if backref:
+1 -1
View File
@@ -1561,7 +1561,7 @@ class Bundle(
_propagate_attrs: _PropagateAttrsType = util.immutabledict()
proxy_set = util.EMPTY_SET # type: ignore
proxy_set = util.EMPTY_SET
exprs: List[_ColumnsClauseElement]
+2 -6
View File
@@ -237,15 +237,11 @@ class _WriteOnlyAttributeImpl(
return _DynamicCollectionAdapter(data) # type: ignore[return-value]
@util.memoized_property
def _append_token( # type:ignore[override]
self,
) -> attributes.AttributeEventToken:
def _append_token(self) -> attributes.AttributeEventToken:
return attributes.AttributeEventToken(self, attributes.OP_APPEND)
@util.memoized_property
def _remove_token( # type:ignore[override]
self,
) -> attributes.AttributeEventToken:
def _remove_token(self) -> attributes.AttributeEventToken:
return attributes.AttributeEventToken(self, attributes.OP_REMOVE)
def fire_append_event(
+3 -3
View File
@@ -60,7 +60,7 @@ class QueuePool(Pool):
"""
_is_asyncio = False # type: ignore[assignment]
_is_asyncio = False
_queue_class: Type[sqla_queue.QueueCommon[ConnectionPoolEntry]] = (
sqla_queue.Queue
@@ -267,7 +267,7 @@ class AsyncAdaptedQueuePool(QueuePool):
"""
_is_asyncio = True # type: ignore[assignment]
_is_asyncio = True
_queue_class: Type[sqla_queue.QueueCommon[ConnectionPoolEntry]] = (
sqla_queue.AsyncAdaptedQueue
)
@@ -350,7 +350,7 @@ class SingletonThreadPool(Pool):
"""
_is_asyncio = False # type: ignore[assignment]
_is_asyncio = False
def __init__(
self,
+1 -1
View File
@@ -30,7 +30,7 @@ except ModuleNotFoundError:
def _is_compiled() -> bool:
"""Utility function to indicate if this module is compiled or not."""
return cython.compiled # type: ignore[no-any-return]
return cython.compiled # type: ignore[no-any-return,unused-ignore]
# END GENERATED CYTHON IMPORT
+1 -1
View File
@@ -852,7 +852,7 @@ class InElementImpl(RoleImpl):
)
@util.preload_module("sqlalchemy.sql.elements")
def _literal_coercion(self, element, *, expr, operator, **kw):
def _literal_coercion(self, element, *, expr, operator, **kw): # type: ignore[override] # noqa: E501
if util.is_non_string_iterable(element):
non_literal_expressions: Dict[
Optional[_ColumnExpressionArgument[Any]],
+2 -2
View File
@@ -4205,7 +4205,7 @@ class SQLCompiler(Compiled):
if self.preparer._requires_quotes(cte_name):
cte_name = self.preparer.quote(cte_name)
text += self.get_render_as_alias_suffix(cte_name)
return text
return text # type: ignore[no-any-return]
else:
return self.preparer.format_alias(cte, cte_name)
@@ -6363,7 +6363,7 @@ class SQLCompiler(Compiled):
self.stack.pop(-1)
return text
return text # type: ignore[no-any-return]
def delete_extra_from_clause(
self, delete_stmt, from_table, extra_froms, from_hints, **kw
+1 -1
View File
@@ -439,7 +439,7 @@ class _CreateDropBase(ExecutableDDLElement, Generic[_SI]):
self._ddl_if = getattr(element, "_ddl_if", None)
@property
def stringify_dialect(self):
def stringify_dialect(self): # type: ignore[override]
assert not isinstance(self.element, str)
return self.element.create_drop_stringify_dialect
+6 -5
View File
@@ -463,7 +463,7 @@ class ClauseElement(
return self
@property
def _constructor(self):
def _constructor(self): # type: ignore[override]
"""return the 'constructor' for this ClauseElement.
This is for the purposes for creating a new object of
@@ -698,6 +698,7 @@ class ClauseElement(
else:
elem_cache_key = None
extracted_params: Optional[Sequence[BindParameter[Any]]]
if elem_cache_key is not None:
if TYPE_CHECKING:
assert compiled_cache is not None
@@ -2327,7 +2328,7 @@ class TextClause(
_allow_label_resolve = False
@property
def _is_star(self):
def _is_star(self): # type: ignore[override]
return self.text == "*"
def __init__(self, text: str):
@@ -4867,11 +4868,11 @@ class Label(roles.LabeledColumnExprRole[_T], NamedColumn[_T]):
return self
@property
def primary_key(self):
def primary_key(self): # type: ignore[override]
return self.element.primary_key
@property
def foreign_keys(self):
def foreign_keys(self): # type: ignore[override]
return self.element.foreign_keys
def _copy_internals(
@@ -5004,7 +5005,7 @@ class ColumnClause(
_is_multiparam_column = False
@property
def _is_star(self):
def _is_star(self): # type: ignore[override]
return self.is_literal and self.name == "*"
def __init__(
+11 -9
View File
@@ -300,7 +300,9 @@ class LambdaElement(elements.ClauseElement):
while lambda_element is not None:
rec = lambda_element._rec
if rec.bindparam_trackers:
tracker_instrumented_fn = rec.tracker_instrumented_fn
tracker_instrumented_fn = (
rec.tracker_instrumented_fn # type:ignore [union-attr] # noqa: E501
)
for tracker in rec.bindparam_trackers:
tracker(
lambda_element.fn,
@@ -602,7 +604,7 @@ class StatementLambdaElement(
return self._rec_expected_expr
@property
def _with_options(self):
def _with_options(self): # type: ignore[override]
return self._proxied._with_options
@property
@@ -610,7 +612,7 @@ class StatementLambdaElement(
return self._proxied._effective_plugin_target
@property
def _execution_options(self):
def _execution_options(self): # type: ignore[override]
return self._proxied._execution_options
@property
@@ -618,27 +620,27 @@ class StatementLambdaElement(
return self._proxied._all_selected_columns
@property
def is_select(self):
def is_select(self): # type: ignore[override]
return self._proxied.is_select
@property
def is_update(self):
def is_update(self): # type: ignore[override]
return self._proxied.is_update
@property
def is_insert(self):
def is_insert(self): # type: ignore[override]
return self._proxied.is_insert
@property
def is_text(self):
def is_text(self): # type: ignore[override]
return self._proxied.is_text
@property
def is_delete(self):
def is_delete(self): # type: ignore[override]
return self._proxied.is_delete
@property
def is_dml(self):
def is_dml(self): # type: ignore[override]
return self._proxied.is_dml
def spoil(self) -> NullLambdaStatement:
+2 -2
View File
@@ -477,7 +477,7 @@ class Table(
table.dispatch.before_parent_attach(table, metadata)
metadata._add_table(name, schema, table)
try:
table.__init__(name, metadata, *args, _no_init=False, **kw)
table.__init__(name, metadata, *args, _no_init=False, **kw) # type: ignore[misc] # noqa: E501
table.dispatch.after_parent_attach(table, metadata)
return table
except Exception:
@@ -2239,7 +2239,7 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]):
return _DefaultDescriptionTuple._from_column_default(self.onupdate)
@util.memoized_property
def _gen_static_annotations_cache_key(self) -> bool: # type: ignore
def _gen_static_annotations_cache_key(self) -> bool:
"""special attribute used by cache key gen, if true, we will
use a static cache key for the annotations dictionary, else we
will generate a new cache key for annotations each time.
+4 -4
View File
@@ -1678,14 +1678,14 @@ class Enum(String, SchemaType, Emulated, TypeEngine[Union[str, enum.Enum]]):
)
@property
def sort_key_function(self):
def sort_key_function(self): # type: ignore[override]
if self._sort_key_function is NO_ARG:
return self._db_value_for_elem
else:
return self._sort_key_function
@property
def native(self):
def native(self): # type: ignore[override]
return self.native_enum
def _db_value_for_elem(self, elem):
@@ -2762,7 +2762,7 @@ class JSON(Indexable, TypeEngine[Any]):
comparator_factory = Comparator
@property # type: ignore # mypy property bug
@property
def should_evaluate_none(self):
"""Alias of :attr:`_types.JSON.none_as_null`"""
return not self.none_as_null
@@ -3709,7 +3709,7 @@ class Uuid(Emulated, TypeEngine[_UUID_RETURN]):
return _python_UUID if self.as_uuid else str
@property
def native(self):
def native(self): # type: ignore[override]
return self.native_uuid
def coerce_compared_value(self, op, value):
+1 -1
View File
@@ -37,7 +37,7 @@ except ModuleNotFoundError:
def _is_compiled() -> bool:
"""Utility function to indicate if this module is compiled or not."""
return cython.compiled # type: ignore[no-any-return]
return cython.compiled # type: ignore[no-any-return,unused-ignore]
# END GENERATED CYTHON IMPORT
+1 -1
View File
@@ -30,7 +30,7 @@ except ModuleNotFoundError:
def _is_compiled() -> bool:
"""Utility function to indicate if this module is compiled or not."""
return cython.compiled # type: ignore[no-any-return]
return cython.compiled # type: ignore[no-any-return,unused-ignore]
# END GENERATED CYTHON IMPORT
@@ -21,7 +21,10 @@ from sqlalchemy.sql.elements import SQLCoreOperations
class ParentProtocol(Protocol):
name: Mapped[str]
# Read-only for simplicity, mutable protocol members are complicated,
# see https://mypy.readthedocs.io/en/latest/common_issues.html#covariant-subtyping-of-mutable-protocol-members-is-rejected
@property
def name(self) -> Mapped[str]: ...
class ChildProtocol(Protocol):
+1 -1
View File
@@ -27,7 +27,7 @@ except ModuleNotFoundError:
def _is_compiled() -> bool:
"""Utility function to indicate if this module is compiled or not."""
return cython.compiled # type: ignore[no-any-return]
return cython.compiled # type: ignore[no-any-return,unused-ignore]
# END GENERATED CYTHON IMPORT\