From: Federico Caselli Date: Tue, 12 Sep 2023 19:56:15 +0000 (+0200) Subject: remove unused type ignores X-Git-Tag: rel_2_0_21~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0be00601c0f7174c58bb6b34df0d90376a5051d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git remove unused type ignores Change-Id: Id212e8b4ff7427872ead8fd409a68408813f7d76 --- diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index 669a8393e4..49712a57c4 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -227,7 +227,7 @@ class PyODBCConnector(Connector): def get_isolation_level_values( self, dbapi_connection: interfaces.DBAPIConnection ) -> List[IsolationLevel]: - return super().get_isolation_level_values(dbapi_connection) + [ # type: ignore # noqa: E501 + return super().get_isolation_level_values(dbapi_connection) + [ "AUTOCOMMIT" ] diff --git a/lib/sqlalchemy/dialects/__init__.py b/lib/sqlalchemy/dialects/__init__.py index 76b2263063..055d087cf2 100644 --- a/lib/sqlalchemy/dialects/__init__.py +++ b/lib/sqlalchemy/dialects/__init__.py @@ -51,7 +51,7 @@ def _auto_fn(name: str) -> Optional[Callable[[], Type[Dialect]]]: if hasattr(module, driver): module = getattr(module, driver) - return lambda: module.dialect # type: ignore + return lambda: module.dialect else: return None diff --git a/lib/sqlalchemy/dialects/postgresql/ranges.py b/lib/sqlalchemy/dialects/postgresql/ranges.py index 2cd1552a73..f1c29897d0 100644 --- a/lib/sqlalchemy/dialects/postgresql/ranges.py +++ b/lib/sqlalchemy/dialects/postgresql/ranges.py @@ -293,7 +293,7 @@ class Range(Generic[_T]): else: return 0 - def __eq__(self, other: Any) -> bool: # type: ignore[override] # noqa: E501 + def __eq__(self, other: Any) -> bool: """Compare this range to the `other` taking into account bounds inclusivity, returning ``True`` if they are equal. """ diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 4b8dd8797a..e9f1efbe63 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -135,7 +135,7 @@ class DefaultDialect(Dialect): # most DBAPIs happy with this for execute(). # not cx_oracle. - execute_sequence_format = tuple # type: ignore + execute_sequence_format = tuple supports_schemas = True supports_views = True @@ -2232,7 +2232,7 @@ class DefaultExecutionContext(ExecutionContext): and compile_state._has_multi_parameters ): if column._is_multiparam_column: - index = column.index + 1 # type: ignore + index = column.index + 1 d = {column.original.key: parameters[column.key]} else: d = {column.key: parameters[column.key]} @@ -2304,7 +2304,7 @@ class DefaultExecutionContext(ExecutionContext): param[param_key] = arg elif is_callable: self.current_column = c - param[param_key] = arg(self) # type: ignore + param[param_key] = arg(self) else: val = fallback(c) if val is not None: diff --git a/lib/sqlalchemy/engine/events.py b/lib/sqlalchemy/engine/events.py index 848f39733a..aac756d18a 100644 --- a/lib/sqlalchemy/engine/events.py +++ b/lib/sqlalchemy/engine/events.py @@ -131,7 +131,7 @@ class ConnectionEvents(event.Events[ConnectionEventsTarget]): if default_dispatch is None and hasattr( target, "_no_async_engine_events" ): - target._no_async_engine_events() # type: ignore + target._no_async_engine_events() return default_dispatch @@ -640,7 +640,7 @@ class DialectEvents(event.Events[Dialect]): _dispatch_target = Dialect @classmethod - def _listen( # type: ignore + def _listen( cls, event_key: event._EventKey[Dialect], *, diff --git a/lib/sqlalchemy/engine/mock.py b/lib/sqlalchemy/engine/mock.py index b80eab516f..618ea1d85e 100644 --- a/lib/sqlalchemy/engine/mock.py +++ b/lib/sqlalchemy/engine/mock.py @@ -126,6 +126,6 @@ def create_mock_engine( dialect_args[k] = kw.pop(k) # create dialect - dialect = dialect_cls(**dialect_args) # type: ignore + dialect = dialect_cls(**dialect_args) return MockConnection(dialect, executor) diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index 4035901aed..6d2a8a29fd 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -230,7 +230,7 @@ class Inspector(inspection.Inspectable["Inspector"]): cls, init: Callable[..., Any], bind: Union[Engine, Connection] ) -> Inspector: if hasattr(bind.dialect, "inspector"): - cls = bind.dialect.inspector # type: ignore[attr-defined] + cls = bind.dialect.inspector self = cls.__new__(cls) init(self, bind) @@ -240,7 +240,7 @@ class Inspector(inspection.Inspectable["Inspector"]): if hasattr(bind, "exec_driver_sql"): self._init_connection(bind) # type: ignore[arg-type] else: - self._init_engine(bind) # type: ignore[arg-type] + self._init_engine(bind) def _init_engine(self, engine: Engine) -> None: self.bind = self.engine = engine @@ -1627,9 +1627,7 @@ class Inspector(inspection.Inspectable["Inspector"]): orig_name = col_d["name"] table.metadata.dispatch.column_reflect(self, table, col_d) - table.dispatch.column_reflect( # type: ignore[attr-defined] - self, table, col_d - ) + table.dispatch.column_reflect(self, table, col_d) # fetch name again as column_reflect is allowed to # change it @@ -2038,7 +2036,7 @@ class ReflectionDefaults: @classmethod def pk_constraint(cls) -> ReflectedPrimaryKeyConstraint: - return { # type: ignore # pep-655 not supported + return { "name": None, "constrained_columns": [], } diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 1c9cc504b1..132ae88b66 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -373,7 +373,7 @@ class SimpleResultMetaData(ResultMetaData): indexes: Sequence[int] new_keys: Sequence[str] extra: Sequence[Any] - indexes, new_keys, extra = zip(*metadata_for_keys) # type: ignore + indexes, new_keys, extra = zip(*metadata_for_keys) if self._translated_indexes: indexes = [self._translated_indexes[idx] for idx in indexes] @@ -459,7 +459,7 @@ class ResultInternal(InPlaceGenerative, Generic[_R]): else: _proc = Row - def process_row( # type: ignore + def process_row( metadata: ResultMetaData, processors: Optional[_ProcessorsType], key_to_index: Mapping[_KeyType, int], diff --git a/lib/sqlalchemy/engine/util.py b/lib/sqlalchemy/engine/util.py index b0a54f97e5..9b147a7014 100644 --- a/lib/sqlalchemy/engine/util.py +++ b/lib/sqlalchemy/engine/util.py @@ -48,7 +48,7 @@ def connection_memoize(key: str) -> Callable[[_C], _C]: connection.info[key] = val = fn(self, connection) return val - return decorated # type: ignore + return decorated class _TConsSubject(Protocol): diff --git a/lib/sqlalchemy/event/base.py b/lib/sqlalchemy/event/base.py index 2c32b043e9..f92b2ede3c 100644 --- a/lib/sqlalchemy/event/base.py +++ b/lib/sqlalchemy/event/base.py @@ -301,7 +301,7 @@ class _HasEventsDispatch(Generic[_ET]): "Type[_Dispatch[_ET]]", type( "%sDispatch" % classname, - (dispatch_base,), # type: ignore + (dispatch_base,), {"__slots__": event_names}, ), ) @@ -323,7 +323,7 @@ class _HasEventsDispatch(Generic[_ET]): assert dispatch_target_cls is not None if ( hasattr(dispatch_target_cls, "__slots__") - and "_slots_dispatch" in dispatch_target_cls.__slots__ # type: ignore # noqa: E501 + and "_slots_dispatch" in dispatch_target_cls.__slots__ ): dispatch_target_cls.dispatch = slots_dispatcher(cls) else: diff --git a/lib/sqlalchemy/event/registry.py b/lib/sqlalchemy/event/registry.py index 8e4a266154..fb2fed815f 100644 --- a/lib/sqlalchemy/event/registry.py +++ b/lib/sqlalchemy/event/registry.py @@ -241,7 +241,7 @@ class _EventKey(Generic[_ET]): ): self.target = target self.identifier = identifier - self.fn = fn # type: ignore[assignment] + self.fn = fn if isinstance(fn, types.MethodType): self.fn_key = id(fn.__func__), id(fn.__self__) else: diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 38755c8fa3..31df134534 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -1047,7 +1047,7 @@ class AssociationProxyInstance(SQLORMOperations[_T]): target_assoc = self._unwrap_target_assoc_proxy if target_assoc is not None: - inner = target_assoc._criterion_exists( # type: ignore + inner = target_assoc._criterion_exists( criterion=criterion, **kwargs ) return self._comparator._criterion_exists(inner) @@ -1961,7 +1961,7 @@ class _AssociationSet(_AssociationSingleItem[_T], MutableSet[_T]): return set(self).symmetric_difference(__s) def __xor__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: - return self.symmetric_difference(s) # type: ignore + return self.symmetric_difference(s) def symmetric_difference_update(self, other: Iterable[Any]) -> None: want, have = self.symmetric_difference(other), set(self) diff --git a/lib/sqlalchemy/ext/asyncio/base.py b/lib/sqlalchemy/ext/asyncio/base.py index 1fecf60abd..1c8707c780 100644 --- a/lib/sqlalchemy/ext/asyncio/base.py +++ b/lib/sqlalchemy/ext/asyncio/base.py @@ -58,9 +58,7 @@ class ReversibleProxy(Generic[_PT]): ) proxy_ref = weakref.ref( self, - functools.partial( # type: ignore - ReversibleProxy._target_gced, target_ref - ), + functools.partial(ReversibleProxy._target_gced, target_ref), ) ReversibleProxy._proxy_objects[target_ref] = proxy_ref @@ -124,7 +122,7 @@ class StartableContext(Awaitable[_T_co], abc.ABC): return self.start().__await__() async def __aenter__(self) -> _T_co: - return await self.start(is_ctxmanager=True) # type: ignore + return await self.start(is_ctxmanager=True) @abc.abstractmethod async def __aexit__( diff --git a/lib/sqlalchemy/ext/asyncio/result.py b/lib/sqlalchemy/ext/asyncio/result.py index 3dcb1cfd08..a13e106ff3 100644 --- a/lib/sqlalchemy/ext/asyncio/result.py +++ b/lib/sqlalchemy/ext/asyncio/result.py @@ -60,7 +60,7 @@ class AsyncCommon(FilterResult[_R]): .. versionadded:: 2.0.0b3 """ - return self._real_result.closed # type: ignore + return self._real_result.closed class AsyncResult(_WithKeys, AsyncCommon[Row[_TP]]): diff --git a/lib/sqlalchemy/ext/hybrid.py b/lib/sqlalchemy/ext/hybrid.py index 1ac6fafc11..722c9bd563 100644 --- a/lib/sqlalchemy/ext/hybrid.py +++ b/lib/sqlalchemy/ext/hybrid.py @@ -1516,7 +1516,7 @@ class ExprComparator(Comparator[_T]): def operate( self, op: OperatorType, *other: Any, **kwargs: Any ) -> ColumnElement[Any]: - return op(self.expression, *other, **kwargs) # type: ignore + return op(self.expression, *other, **kwargs) def reverse_operate( self, op: OperatorType, other: Any, **kwargs: Any diff --git a/lib/sqlalchemy/ext/mypy/names.py b/lib/sqlalchemy/ext/mypy/names.py index 989f255923..ae55ca47b0 100644 --- a/lib/sqlalchemy/ext/mypy/names.py +++ b/lib/sqlalchemy/ext/mypy/names.py @@ -34,24 +34,23 @@ from mypy.types import UnboundType from ... import util -COLUMN: int = util.symbol("COLUMN") # type: ignore -RELATIONSHIP: int = util.symbol("RELATIONSHIP") # type: ignore -REGISTRY: int = util.symbol("REGISTRY") # type: ignore -COLUMN_PROPERTY: int = util.symbol("COLUMN_PROPERTY") # type: ignore -TYPEENGINE: int = util.symbol("TYPEENGNE") # type: ignore -MAPPED: int = util.symbol("MAPPED") # type: ignore -DECLARATIVE_BASE: int = util.symbol("DECLARATIVE_BASE") # type: ignore -DECLARATIVE_META: int = util.symbol("DECLARATIVE_META") # type: ignore -MAPPED_DECORATOR: int = util.symbol("MAPPED_DECORATOR") # type: ignore -COLUMN_PROPERTY: int = util.symbol("COLUMN_PROPERTY") # type: ignore -SYNONYM_PROPERTY: int = util.symbol("SYNONYM_PROPERTY") # type: ignore -COMPOSITE_PROPERTY: int = util.symbol("COMPOSITE_PROPERTY") # type: ignore -DECLARED_ATTR: int = util.symbol("DECLARED_ATTR") # type: ignore -MAPPER_PROPERTY: int = util.symbol("MAPPER_PROPERTY") # type: ignore -AS_DECLARATIVE: int = util.symbol("AS_DECLARATIVE") # type: ignore -AS_DECLARATIVE_BASE: int = util.symbol("AS_DECLARATIVE_BASE") # type: ignore -DECLARATIVE_MIXIN: int = util.symbol("DECLARATIVE_MIXIN") # type: ignore -QUERY_EXPRESSION: int = util.symbol("QUERY_EXPRESSION") # type: ignore +COLUMN: int = util.symbol("COLUMN") +RELATIONSHIP: int = util.symbol("RELATIONSHIP") +REGISTRY: int = util.symbol("REGISTRY") +COLUMN_PROPERTY: int = util.symbol("COLUMN_PROPERTY") +TYPEENGINE: int = util.symbol("TYPEENGNE") +MAPPED: int = util.symbol("MAPPED") +DECLARATIVE_BASE: int = util.symbol("DECLARATIVE_BASE") +DECLARATIVE_META: int = util.symbol("DECLARATIVE_META") +MAPPED_DECORATOR: int = util.symbol("MAPPED_DECORATOR") +SYNONYM_PROPERTY: int = util.symbol("SYNONYM_PROPERTY") +COMPOSITE_PROPERTY: int = util.symbol("COMPOSITE_PROPERTY") +DECLARED_ATTR: int = util.symbol("DECLARED_ATTR") +MAPPER_PROPERTY: int = util.symbol("MAPPER_PROPERTY") +AS_DECLARATIVE: int = util.symbol("AS_DECLARATIVE") +AS_DECLARATIVE_BASE: int = util.symbol("AS_DECLARATIVE_BASE") +DECLARATIVE_MIXIN: int = util.symbol("DECLARATIVE_MIXIN") +QUERY_EXPRESSION: int = util.symbol("QUERY_EXPRESSION") # names that must succeed with mypy.api.named_type NAMED_TYPE_BUILTINS_OBJECT = "builtins.object" diff --git a/lib/sqlalchemy/ext/mypy/util.py b/lib/sqlalchemy/ext/mypy/util.py index fe44021236..238c82a54f 100644 --- a/lib/sqlalchemy/ext/mypy/util.py +++ b/lib/sqlalchemy/ext/mypy/util.py @@ -173,7 +173,7 @@ def get_mapped_attributes( def format_type(typ_: Type, options: Options) -> str: if mypy_14: - return _mypy_format_type(typ_, options) # type: ignore + return _mypy_format_type(typ_, options) else: return _mypy_format_type(typ_) # type: ignore diff --git a/lib/sqlalchemy/log.py b/lib/sqlalchemy/log.py index f1e2cf12c7..8de6d188ce 100644 --- a/lib/sqlalchemy/log.py +++ b/lib/sqlalchemy/log.py @@ -75,10 +75,10 @@ def _qual_logger_name_for_cls(cls: Type[Identified]) -> str: def class_logger(cls: Type[_IT]) -> Type[_IT]: logger = logging.getLogger(_qual_logger_name_for_cls(cls)) - cls._should_log_debug = lambda self: logger.isEnabledFor( # type: ignore[assignment] # noqa: E501 + cls._should_log_debug = lambda self: logger.isEnabledFor( # type: ignore[method-assign] # noqa: E501 logging.DEBUG ) - cls._should_log_info = lambda self: logger.isEnabledFor( # type: ignore[assignment] # noqa: E501 + cls._should_log_info = lambda self: logger.isEnabledFor( # type: ignore[method-assign] # noqa: E501 logging.INFO ) cls.logger = logger diff --git a/lib/sqlalchemy/orm/_typing.py b/lib/sqlalchemy/orm/_typing.py index cc4233be11..60664283da 100644 --- a/lib/sqlalchemy/orm/_typing.py +++ b/lib/sqlalchemy/orm/_typing.py @@ -119,7 +119,7 @@ class _LoaderCallable(Protocol): def is_orm_option( opt: ExecutableOption, ) -> TypeGuard[ORMOption]: - return not opt._is_core # type: ignore + return not opt._is_core def is_user_defined_option( diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index b1bda22819..00d3f50792 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -335,7 +335,7 @@ class QueryableAttribute( entity_namespace = self._entity_namespace assert isinstance(entity_namespace, HasCacheKey) - if self.key is _UNKNOWN_ATTR_KEY: # type: ignore[comparison-overlap] + if self.key is _UNKNOWN_ATTR_KEY: annotations = {"entity_namespace": entity_namespace} else: annotations = { @@ -450,12 +450,12 @@ class QueryableAttribute( def operate( self, op: OperatorType, *other: Any, **kwargs: Any ) -> ColumnElement[Any]: - return op(self.comparator, *other, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501 + return op(self.comparator, *other, **kwargs) # type: ignore[no-any-return] # noqa: E501 def reverse_operate( self, op: OperatorType, other: Any, **kwargs: Any ) -> ColumnElement[Any]: - return op(other, self.comparator, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501 + return op(other, self.comparator, **kwargs) # type: ignore[no-any-return] # noqa: E501 def hasparent( self, state: InstanceState[Any], optimistic: bool = False @@ -521,16 +521,16 @@ class InstrumentedAttribute(QueryableAttribute[_T]): # InstrumentedAttribute, while still keeping classlevel # __doc__ correct - @util.rw_hybridproperty # type: ignore - def __doc__(self) -> Optional[str]: # type: ignore + @util.rw_hybridproperty + def __doc__(self) -> Optional[str]: return self._doc @__doc__.setter # type: ignore - def __doc__(self, value: Optional[str]) -> None: # type: ignore + def __doc__(self, value: Optional[str]) -> None: self._doc = value @__doc__.classlevel # type: ignore - def __doc__(cls) -> Optional[str]: # type: ignore + def __doc__(cls) -> Optional[str]: return super().__doc__ def __set__(self, instance: object, value: Any) -> None: @@ -1941,7 +1941,7 @@ class CollectionAttributeImpl(HasCollectionAdapter, AttributeImpl): and "None" or iterable.__class__.__name__ ) - wanted = self._duck_typed_as.__name__ # type: ignore + wanted = self._duck_typed_as.__name__ raise TypeError( "Incompatible collection type: %s is not %s-like" % (given, wanted) diff --git a/lib/sqlalchemy/orm/decl_api.py b/lib/sqlalchemy/orm/decl_api.py index 1b378f3c8d..80c85f13ad 100644 --- a/lib/sqlalchemy/orm/decl_api.py +++ b/lib/sqlalchemy/orm/decl_api.py @@ -253,7 +253,7 @@ class _declared_attr_common: # which seems to help typing tools interpret the fn as a classmethod # for situations where needed if isinstance(fn, classmethod): - fn = fn.__func__ # type: ignore + fn = fn.__func__ self.fget = fn self._cascading = cascading @@ -281,11 +281,11 @@ class _declared_attr_common: "Unmanaged access of declarative attribute %s from " "non-mapped class %s" % (self.fget.__name__, cls.__name__) ) - return self.fget(cls) # type: ignore + return self.fget(cls) elif manager.is_mapped: # the class is mapped, which means we're outside of the declarative # scan setup, just run the function. - return self.fget(cls) # type: ignore + return self.fget(cls) # here, we are inside of the declarative scan. use the registry # that is tracking the values of these attributes. @@ -297,10 +297,10 @@ class _declared_attr_common: reg = declarative_scan.declared_attr_reg if self in reg: - return reg[self] # type: ignore + return reg[self] else: reg[self] = obj = self.fget(cls) - return obj # type: ignore + return obj class _declared_directive(_declared_attr_common, Generic[_T]): @@ -558,12 +558,12 @@ def _setup_declarative_base(cls: Type[Any]) -> None: reg = registry( metadata=metadata, type_annotation_map=type_annotation_map ) - cls.registry = reg # type: ignore + cls.registry = reg - cls._sa_registry = reg # type: ignore + cls._sa_registry = reg if "metadata" not in cls.__dict__: - cls.metadata = cls.registry.metadata # type: ignore + cls.metadata = cls.registry.metadata if getattr(cls, "__init__", object.__init__) is object.__init__: cls.__init__ = cls.registry.constructor @@ -609,7 +609,7 @@ class MappedAsDataclass(metaclass=DCTransformDeclarative): current_transforms: _DataclassArguments if hasattr(cls, "_sa_apply_dc_transforms"): - current = cls._sa_apply_dc_transforms # type: ignore[attr-defined] + current = cls._sa_apply_dc_transforms _ClassScanMapperConfig._assert_dc_arguments(current) @@ -1274,7 +1274,7 @@ class registry: sql_type = sqltypes._type_map_get(pt) # type: ignore # noqa: E501 if sql_type is not None: - sql_type_inst = sqltypes.to_instance(sql_type) # type: ignore + sql_type_inst = sqltypes.to_instance(sql_type) # ... this additional step will reject most # type -> supertype matches, such as if we had diff --git a/lib/sqlalchemy/orm/decl_base.py b/lib/sqlalchemy/orm/decl_base.py index 816c7a8fd4..9d10599499 100644 --- a/lib/sqlalchemy/orm/decl_base.py +++ b/lib/sqlalchemy/orm/decl_base.py @@ -1609,7 +1609,7 @@ class _ClassScanMapperConfig(_MapperConfig): setattr(cls, k, value) continue - our_stuff[k] = value # type: ignore + our_stuff[k] = value def _extract_declared_columns(self) -> None: our_stuff = self.properties @@ -1979,7 +1979,7 @@ class _DeferredMapperConfig(_ClassScanMapperConfig): # mypy disallows plain property override of variable @property # type: ignore - def cls(self) -> Type[Any]: # type: ignore + def cls(self) -> Type[Any]: return self._cls() # type: ignore @cls.setter @@ -1999,7 +1999,7 @@ class _DeferredMapperConfig(_ClassScanMapperConfig): @classmethod def raise_unmapped_for_cls(cls, class_: Type[Any]) -> NoReturn: if hasattr(class_, "_sa_raise_deferred_config"): - class_._sa_raise_deferred_config() # type: ignore + class_._sa_raise_deferred_config() raise orm_exc.UnmappedClassError( class_, diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index e7c9de2a62..c1fe9de85c 100644 --- a/lib/sqlalchemy/orm/descriptor_props.py +++ b/lib/sqlalchemy/orm/descriptor_props.py @@ -425,7 +425,7 @@ class CompositeProperty( elif hasattr(self.composite_class, "__composite_values__"): _composite_getters[ self.composite_class - ] = lambda obj: obj.__composite_values__() # type: ignore + ] = lambda obj: obj.__composite_values__() @util.preload_module("sqlalchemy.orm.properties") @util.preload_module("sqlalchemy.orm.decl_base") @@ -628,7 +628,7 @@ class CompositeProperty( proxy_attr = self.parent.class_manager[self.key] proxy_attr.impl.dispatch = proxy_attr.dispatch # type: ignore - proxy_attr.impl.dispatch._active_history = self.active_history # type: ignore # noqa: E501 + proxy_attr.impl.dispatch._active_history = self.active_history # TODO: need a deserialize hook here @@ -806,16 +806,16 @@ class CompositeProperty( def __ne__(self, other: Any) -> ColumnElement[bool]: # type: ignore[override] # noqa: E501 return self._compare(operators.ne, other) - def __lt__(self, other: Any) -> ColumnElement[bool]: # type: ignore[override] # noqa: E501 + def __lt__(self, other: Any) -> ColumnElement[bool]: return self._compare(operators.lt, other) - def __gt__(self, other: Any) -> ColumnElement[bool]: # type: ignore[override] # noqa: E501 + def __gt__(self, other: Any) -> ColumnElement[bool]: return self._compare(operators.gt, other) - def __le__(self, other: Any) -> ColumnElement[bool]: # type: ignore[override] # noqa: E501 + def __le__(self, other: Any) -> ColumnElement[bool]: return self._compare(operators.le, other) - def __ge__(self, other: Any) -> ColumnElement[bool]: # type: ignore[override] # noqa: E501 + def __ge__(self, other: Any) -> ColumnElement[bool]: return self._compare(operators.ge, other) # what might be interesting would be if we create @@ -839,8 +839,8 @@ class CompositeProperty( ] if self._adapt_to_entity: assert self.adapter is not None - comparisons = [self.adapter(x) for x in comparisons] # type: ignore # noqa: E501 - return sql.and_(*comparisons) # type: ignore + comparisons = [self.adapter(x) for x in comparisons] + return sql.and_(*comparisons) def __str__(self) -> str: return str(self.parent.class_.__name__) + "." + self.key diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py index 1b755a27ab..b12d80ac4f 100644 --- a/lib/sqlalchemy/orm/instrumentation.py +++ b/lib/sqlalchemy/orm/instrumentation.py @@ -138,7 +138,7 @@ class ClassManager( def deferred_scalar_loader(self): return self.expired_attribute_loader - @deferred_scalar_loader.setter # type: ignore[no-redef] + @deferred_scalar_loader.setter @util.deprecated( "1.4", message="The ClassManager.deferred_scalar_loader attribute is now " @@ -204,7 +204,7 @@ class ClassManager( init_method: Optional[Callable[..., None]] = None, ) -> None: if mapper: - self.mapper = mapper # type: ignore[assignment] + self.mapper = mapper # if registry: registry._add_manager(self) if declarative_scan: @@ -428,7 +428,7 @@ class ClassManager( for key in list(self.originals): self.uninstall_member(key) - self.mapper = None # type: ignore + self.mapper = None self.dispatch = None # type: ignore self.new_init = None self.info.clear() @@ -506,11 +506,11 @@ class ClassManager( # so that mypy sees that __new__ is present. currently # it's bound to Any as there were other problems not having # it that way but these can be revisited - instance = self.class_.__new__(self.class_) # type: ignore + instance = self.class_.__new__(self.class_) if state is None: state = self._state_constructor(instance, self) self._state_setter(instance, state) - return instance # type: ignore[no-any-return] + return instance def setup_instance( self, instance: _O, state: Optional[InstanceState[_O]] = None diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index daba973cb3..a118b2aa85 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -923,9 +923,7 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators): """ - return self.operate( # type: ignore - PropComparator.any_op, criterion, **kwargs - ) + return self.operate(PropComparator.any_op, criterion, **kwargs) def has( self, @@ -947,9 +945,7 @@ class PropComparator(SQLORMOperations[_T_co], Generic[_T_co], ColumnOperators): """ - return self.operate( # type: ignore - PropComparator.has_op, criterion, **kwargs - ) + return self.operate(PropComparator.has_op, criterion, **kwargs) class StrategizedProperty(MapperProperty[_T]): diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 06671a5e12..a83c70043a 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -786,7 +786,7 @@ class Mapper( # interim - polymorphic_on is further refined in # _configure_polymorphic_setter - self.polymorphic_on = ( # type: ignore + self.polymorphic_on = ( coercions.expect( # type: ignore roles.ColumnArgumentOrKeyRole, polymorphic_on, @@ -1400,7 +1400,7 @@ class Mapper( self.with_polymorphic = None if self.with_polymorphic and self.with_polymorphic[1] is not None: - self.with_polymorphic = ( # type: ignore + self.with_polymorphic = ( self.with_polymorphic[0], coercions.expect( roles.StrictFromClauseRole, @@ -1504,7 +1504,7 @@ class Mapper( manager = instrumentation.register_class( self.class_, mapper=self, - expired_attribute_loader=util.partial( # type: ignore + expired_attribute_loader=util.partial( loading.load_scalar_attributes, self ), # finalize flag means instrument the __init__ method @@ -1610,7 +1610,7 @@ class Mapper( if isinstance(c, str) else c for c in ( - coercions.expect( # type: ignore + coercions.expect( roles.DDLConstraintColumnRole, coerce_pk, argname="primary_key", diff --git a/lib/sqlalchemy/orm/path_registry.py b/lib/sqlalchemy/orm/path_registry.py index 2cd8a1412c..41ca328e1c 100644 --- a/lib/sqlalchemy/orm/path_registry.py +++ b/lib/sqlalchemy/orm/path_registry.py @@ -619,7 +619,7 @@ class PropRegistry(PathRegistry): self._wildcard_path_loader_key = ( "loader", - parent.natural_path + self.prop._wildcard_token, # type: ignore + parent.natural_path + self.prop._wildcard_token, ) self._default_path_loader_key = self.prop._default_path_loader_key self._loader_key = ("loader", self.natural_path) diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 4df5175d07..606cebc40c 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -446,7 +446,7 @@ class ColumnProperty( try: return ce.info # type: ignore except AttributeError: - return self.prop.info # type: ignore + return self.prop.info def _memoized_attr_expressions(self) -> Sequence[NamedColumn[Any]]: """The full sequence of columns referenced by this @@ -475,13 +475,13 @@ class ColumnProperty( def operate( self, op: OperatorType, *other: Any, **kwargs: Any ) -> ColumnElement[Any]: - return op(self.__clause_element__(), *other, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501 + return op(self.__clause_element__(), *other, **kwargs) # type: ignore[no-any-return] # noqa: E501 def reverse_operate( self, op: OperatorType, other: Any, **kwargs: Any ) -> ColumnElement[Any]: col = self.__clause_element__() - return op(col._bind_param(op, other), col, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501 + return op(col._bind_param(op, other), col, **kwargs) # type: ignore[no-any-return] # noqa: E501 def __str__(self) -> str: if not self.parent or not self.key: @@ -639,13 +639,13 @@ class MappedColumn( def operate( self, op: OperatorType, *other: Any, **kwargs: Any ) -> ColumnElement[Any]: - return op(self.__clause_element__(), *other, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501 + return op(self.__clause_element__(), *other, **kwargs) # type: ignore[no-any-return] # noqa: E501 def reverse_operate( self, op: OperatorType, other: Any, **kwargs: Any ) -> ColumnElement[Any]: col = self.__clause_element__() - return op(col._bind_param(op, other), col, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501 + return op(col._bind_param(op, other), col, **kwargs) # type: ignore[no-any-return] # noqa: E501 def found_in_pep593_annotated(self) -> Any: # return a blank mapped_column(). This mapped_column()'s diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 14e75fab94..b1678bce18 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -274,7 +274,7 @@ class Query( self._set_entities(entities) def _set_propagate_attrs(self, values: Mapping[str, Any]) -> Self: - self._propagate_attrs = util.immutabledict(values) # type: ignore + self._propagate_attrs = util.immutabledict(values) return self def _set_entities( @@ -478,7 +478,7 @@ class Query( return self def _clone(self, **kw: Any) -> Self: - return self._generate() # type: ignore + return self._generate() def _get_select_statement_only(self) -> Select[_T]: if self._statement is not None: @@ -1450,7 +1450,7 @@ class Query( q._set_entities(columns) if not q.load_options._yield_per: q.load_options += {"_yield_per": 10} - return iter(q) # type: ignore + return iter(q) @util.deprecated( "1.4", diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index d3a8da042a..191ace48dd 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -1764,7 +1764,7 @@ class RelationshipProperty( argument = de_optionalize_union_types(argument) if hasattr(argument, "__origin__"): - arg_origin = argument.__origin__ # type: ignore + arg_origin = argument.__origin__ if isinstance(arg_origin, type) and issubclass( arg_origin, abc.Collection ): @@ -1786,7 +1786,7 @@ class RelationshipProperty( if argument.__args__: # type: ignore if isinstance(arg_origin, type) and issubclass( - arg_origin, typing.Mapping # type: ignore + arg_origin, typing.Mapping ): type_arg = argument.__args__[-1] # type: ignore else: @@ -1804,7 +1804,7 @@ class RelationshipProperty( f"Generic alias {argument} requires an argument" ) elif hasattr(argument, "__forward_arg__"): - argument = argument.__forward_arg__ # type: ignore + argument = argument.__forward_arg__ argument = resolve_name_to_real_class_name( argument, originating_module @@ -1874,7 +1874,7 @@ class RelationshipProperty( % (self.key, type(resolved_argument)) ) - self.entity = entity # type: ignore + self.entity = entity self.target = self.entity.persist_selectable def _setup_join_conditions(self) -> None: diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index b1ae198592..d9e1f854d7 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -617,8 +617,8 @@ class InstanceState(interfaces.InspectionAttrInfo, Generic[_O]): self.class_ = state_dict["class_"] self.committed_state = state_dict.get("committed_state", {}) - self._pending_mutations = state_dict.get("_pending_mutations", {}) # type: ignore # noqa E501 - self.parents = state_dict.get("parents", {}) # type: ignore + self._pending_mutations = state_dict.get("_pending_mutations", {}) + self.parents = state_dict.get("parents", {}) self.modified = state_dict.get("modified", False) self.expired = state_dict.get("expired", False) if "info" in state_dict: diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index 4371e6116f..005155dd0a 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -1204,7 +1204,7 @@ class AliasedInsp( # IMO mypy should see this one also as returning the same type # we put into it, but it's not return ( - self._adapter.traverse(expr) # type: ignore + self._adapter.traverse(expr) ._annotate(d) ._set_propagate_attrs( {"compile_state_plugin": "orm", "plugin_subject": self} @@ -1397,7 +1397,7 @@ class LoaderCriteriaOption(CriteriaOption): self.deferred_where_criteria = True self.where_criteria = lambdas.DeferredLambdaElement( - where_criteria, # type: ignore + where_criteria, roles.WhereHavingRole, lambda_args=(_WrapUserEntity(wrap_entity),), opts=lambdas.LambdaOptions( @@ -2169,9 +2169,9 @@ def _getitem(iterable_query: Query[Any], item: Any) -> Any: res = iterable_query.slice(start, stop) if step is not None: - return list(res)[None : None : item.step] # type: ignore + return list(res)[None : None : item.step] else: - return list(res) # type: ignore + return list(res) else: if item == -1: _no_negative_indexes() @@ -2380,9 +2380,9 @@ def _extract_mapped_subtype( else: return annotated, None - if len(annotated.__args__) != 1: # type: ignore + if len(annotated.__args__) != 1: raise sa_exc.ArgumentError( "Expected sub-type for Mapped[] annotation" ) - return annotated.__args__[0], annotated.__origin__ # type: ignore + return annotated.__args__[0], annotated.__origin__ diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py index 7f542ae013..915dc400b9 100644 --- a/lib/sqlalchemy/pool/base.py +++ b/lib/sqlalchemy/pool/base.py @@ -323,13 +323,13 @@ class Pool(log.Identified, event.EventTarget): # mypy seems to get super confused assigning functions to # attributes - self._invoke_creator = self._should_wrap_creator(creator) # type: ignore # noqa: E501 + self._invoke_creator = self._should_wrap_creator(creator) @_creator.deleter def _creator(self) -> None: # needed for mock testing del self._creator_arg - del self._invoke_creator # type: ignore[misc] + del self._invoke_creator def _should_wrap_creator( self, creator: Union[_CreatorFnType, _CreatorWRecFnType] @@ -835,7 +835,7 @@ class _ConnectionRecord(ConnectionPoolEntry): # time and invalidation for the logic below to work reliably. if self.dbapi_connection is None: - self.info.clear() # type: ignore # our info is always present + self.info.clear() self.__connect() elif ( self.__pool._recycle > -1 @@ -863,7 +863,7 @@ class _ConnectionRecord(ConnectionPoolEntry): if recycle: self.__close(terminate=True) - self.info.clear() # type: ignore # our info is always present + self.info.clear() self.__connect() diff --git a/lib/sqlalchemy/pool/events.py b/lib/sqlalchemy/pool/events.py index 8366b7bd2a..762418b14f 100644 --- a/lib/sqlalchemy/pool/events.py +++ b/lib/sqlalchemy/pool/events.py @@ -82,7 +82,7 @@ class PoolEvents(event.Events[Pool]): return None @classmethod - def _listen( # type: ignore[override] # would rather keep **kw + def _listen( cls, event_key: event._EventKey[Pool], **kw: Any, diff --git a/lib/sqlalchemy/pool/impl.py b/lib/sqlalchemy/pool/impl.py index 84849edc29..af4f788e27 100644 --- a/lib/sqlalchemy/pool/impl.py +++ b/lib/sqlalchemy/pool/impl.py @@ -386,7 +386,7 @@ class SingletonThreadPool(Pool): def _do_return_conn(self, record: ConnectionPoolEntry) -> None: try: - del self._fairy.current # type: ignore + del self._fairy.current except AttributeError: pass diff --git a/lib/sqlalchemy/sql/_typing.py b/lib/sqlalchemy/sql/_typing.py index a08a770945..c9e183058e 100644 --- a/lib/sqlalchemy/sql/_typing.py +++ b/lib/sqlalchemy/sql/_typing.py @@ -411,7 +411,7 @@ def Nullable( .. versionadded:: 2.0.20 """ - return val # type: ignore + return val @overload diff --git a/lib/sqlalchemy/sql/annotation.py b/lib/sqlalchemy/sql/annotation.py index 4ccde591a9..08ff47d3d6 100644 --- a/lib/sqlalchemy/sql/annotation.py +++ b/lib/sqlalchemy/sql/annotation.py @@ -300,7 +300,7 @@ class Annotated(SupportsAnnotations): def _annotate(self, values: _AnnotationDict) -> Self: _values = self._annotations.union(values) - new = self._with_annotations(_values) # type: ignore + new = self._with_annotations(_values) return new def _with_annotations(self, values: _AnnotationDict) -> Self: diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index 913ab4300d..a1d16f4476 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -273,7 +273,7 @@ def _generative(fn: _Fn) -> _Fn: """ - @util.decorator # type: ignore + @util.decorator def _generative( fn: _Fn, self: _SelfGenerativeType, *args: Any, **kw: Any ) -> _SelfGenerativeType: @@ -299,7 +299,7 @@ def _exclusive_against(*names: str, **kw: Any) -> Callable[[_Fn], _Fn]: for name in names ] - @util.decorator # type: ignore + @util.decorator def check(fn, *args, **kw): # make pylance happy by not including "self" in the argument # list @@ -315,7 +315,7 @@ def _exclusive_against(*names: str, **kw: Any) -> Callable[[_Fn], _Fn]: raise exc.InvalidRequestError(msg) return fn(self, *args, **kw) - return check # type: ignore + return check def _clone(element, **kw): diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 314cbe2167..171dd1f1bd 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -4089,7 +4089,7 @@ class SQLCompiler(Compiled): from_linter.froms[cte._de_clone()] = cte_name if not is_new_cte and embedded_in_current_named_cte: - return self.preparer.format_alias(cte, cte_name) # type: ignore[no-any-return] # noqa: E501 + return self.preparer.format_alias(cte, cte_name) if cte_pre_alias_name: text = self.preparer.format_alias(cte, cte_pre_alias_name) diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py index 544f6771a2..298c50ec0f 100644 --- a/lib/sqlalchemy/sql/crud.py +++ b/lib/sqlalchemy/sql/crud.py @@ -491,10 +491,10 @@ def _key_getters_for_crud_column( key: Union[ColumnClause[Any], str] ) -> Union[str, Tuple[str, str]]: str_key = c_key_role(key) - if hasattr(key, "table") and key.table in _et: # type: ignore + if hasattr(key, "table") and key.table in _et: return (key.table.name, str_key) # type: ignore else: - return str_key # type: ignore + return str_key def _getattr_col_key( col: ColumnClause[Any], @@ -513,7 +513,7 @@ def _key_getters_for_crud_column( return col.key else: - _column_as_key = functools.partial( # type: ignore + _column_as_key = functools.partial( coercions.expect_as_key, roles.DMLColumnRole ) _getattr_col_key = _col_bind_name = operator.attrgetter("key") # type: ignore # noqa: E501 diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py index 09cc54d546..51d2cdcf97 100644 --- a/lib/sqlalchemy/sql/ddl.py +++ b/lib/sqlalchemy/sql/ddl.py @@ -470,7 +470,7 @@ class CreateSchema(_CreateBase): __visit_name__ = "create_schema" - stringify_dialect = "default" # type: ignore + stringify_dialect = "default" def __init__( self, @@ -491,7 +491,7 @@ class DropSchema(_DropBase): __visit_name__ = "drop_schema" - stringify_dialect = "default" # type: ignore + stringify_dialect = "default" def __init__( self, diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 3917b5f023..7f7329f419 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -1606,12 +1606,12 @@ class ColumnElement( *other: Any, **kwargs: Any, ) -> ColumnElement[Any]: - return op(self.comparator, *other, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501 + return op(self.comparator, *other, **kwargs) # type: ignore[no-any-return] # noqa: E501 def reverse_operate( self, op: operators.OperatorType, other: Any, **kwargs: Any ) -> ColumnElement[Any]: - return op(other, self.comparator, **kwargs) # type: ignore[return-value,no-any-return] # noqa: E501 + return op(other, self.comparator, **kwargs) # type: ignore[no-any-return] # noqa: E501 def _bind_param( self, @@ -3125,7 +3125,7 @@ class BooleanClauseList(ExpressionClauseList[bool]): }, *args)'.""", version="1.4", ) - return cls._construct_raw(operator) # type: ignore[no-any-return] + return cls._construct_raw(operator) lcc, convert_clauses = cls._process_clauses_for_boolean( operator, @@ -3155,7 +3155,7 @@ class BooleanClauseList(ExpressionClauseList[bool]): assert lcc # just one element. return it as a single boolean element, # not a list and discard the operator. - return convert_clauses[0] # type: ignore[no-any-return] # noqa: E501 + return convert_clauses[0] @classmethod def _construct_for_whereclause( diff --git a/lib/sqlalchemy/sql/lambdas.py b/lib/sqlalchemy/sql/lambdas.py index 455649cb96..7aef605ac7 100644 --- a/lib/sqlalchemy/sql/lambdas.py +++ b/lib/sqlalchemy/sql/lambdas.py @@ -718,7 +718,7 @@ class LinkedLambdaElement(StatementLambdaElement): opts: Union[Type[LambdaOptions], LambdaOptions], ): self.opts = opts - self.fn = fn # type: ignore[assignment] + self.fn = fn self.parent_lambda = parent_lambda self.tracker_key = parent_lambda.tracker_key + (fn.__code__,) diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py index 6ec150424b..cd878a5957 100644 --- a/lib/sqlalchemy/sql/operators.py +++ b/lib/sqlalchemy/sql/operators.py @@ -307,7 +307,7 @@ class Operators: ) def against(other: Any) -> Operators: - return operator(self, other) # type: ignore + return operator(self, other) return against @@ -570,7 +570,7 @@ class ColumnOperators(Operators): return self.operate(le, other) # TODO: not sure why we have this - __hash__ = Operators.__hash__ # type: ignore + __hash__ = Operators.__hash__ def __eq__(self, other: Any) -> ColumnOperators: # type: ignore[override] """Implement the ``==`` operator. diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 8baf2de6a4..de6507145d 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -1432,7 +1432,7 @@ class Table( elif schema is None: actual_schema = metadata.schema else: - actual_schema = schema # type: ignore + actual_schema = schema key = _get_table_key(name, actual_schema) if key in metadata.tables: util.warn( @@ -2451,14 +2451,8 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]): # Constraint objects plus non-constraint-bound ForeignKey objects args: List[SchemaItem] = [ - c._copy(**kw) - for c in self.constraints - if not c._type_bound # type: ignore - ] + [ - c._copy(**kw) # type: ignore - for c in self.foreign_keys - if not c.constraint - ] + c._copy(**kw) for c in self.constraints if not c._type_bound + ] + [c._copy(**kw) for c in self.foreign_keys if not c.constraint] # ticket #5276 column_kwargs = {} @@ -3972,7 +3966,7 @@ class FetchedValue(SchemaEventTarget): if for_update == self.for_update: return self else: - return self._clone(for_update) # type: ignore + return self._clone(for_update) def _copy(self) -> FetchedValue: return FetchedValue(self.for_update) @@ -4150,7 +4144,7 @@ class Constraint(DialectKWArgs, HasConditionalDDL, SchemaItem): "and will be removed in a future release.", ) def copy(self, **kw: Any) -> Self: - return self._copy(**kw) # type: ignore + return self._copy(**kw) def _copy(self, **kw: Any) -> Self: raise NotImplementedError() @@ -5309,7 +5303,7 @@ _NamingSchemaParameter = Union[ DEFAULT_NAMING_CONVENTION: _NamingSchemaParameter = util.immutabledict( - {"ix": "ix_%(column_0_label)s"} # type: ignore[arg-type] + {"ix": "ix_%(column_0_label)s"} ) diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 71fca7e1f2..c1a47b0cec 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -323,9 +323,7 @@ class Selectable(ReturnsRows): object, returning a copy of this :class:`_expression.FromClause`. """ - return util.preloaded.sql_util.ClauseAdapter(alias).traverse( # type: ignore # noqa: E501 - self - ) + return util.preloaded.sql_util.ClauseAdapter(alias).traverse(self) def corresponding_column( self, column: KeyedColumnElement[Any], require_embedded: bool = False @@ -1420,7 +1418,7 @@ class Join(roles.DMLTableRole, FromClause): continue for fk in sorted( b.foreign_keys, - key=lambda fk: fk.parent._creation_order, # type: ignore + key=lambda fk: fk.parent._creation_order, ): if ( consider_as_foreign_keys is not None @@ -1441,7 +1439,7 @@ class Join(roles.DMLTableRole, FromClause): if left is not b: for fk in sorted( left.foreign_keys, - key=lambda fk: fk.parent._creation_order, # type: ignore + key=lambda fk: fk.parent._creation_order, ): if ( consider_as_foreign_keys is not None @@ -4752,7 +4750,7 @@ class SelectState(util.MemoizedSlots, CompileState): Dict[str, ColumnElement[Any]], ]: with_cols: Dict[str, ColumnElement[Any]] = { - c._tq_label or c.key: c # type: ignore + c._tq_label or c.key: c for c in self.statement._all_selected_columns if c._allow_label_resolve } @@ -5020,7 +5018,7 @@ class _MemoizedSelectEntities( c.__dict__ = {k: v for k, v in self.__dict__.items()} c._is_clone_of = self.__dict__.get("_is_clone_of", self) - return c # type: ignore + return c @classmethod def _generate_for_statement(cls, select_stmt: Select[Any]) -> None: diff --git a/lib/sqlalchemy/sql/traversals.py b/lib/sqlalchemy/sql/traversals.py index 5c782f1db6..5758dff3c4 100644 --- a/lib/sqlalchemy/sql/traversals.py +++ b/lib/sqlalchemy/sql/traversals.py @@ -56,15 +56,15 @@ def _preconfigure_traversals(target_hierarchy: Type[Any]) -> None: if hasattr(cls, "_generate_cache_attrs") and hasattr( cls, "_traverse_internals" ): - cls._generate_cache_attrs() # type: ignore + cls._generate_cache_attrs() _copy_internals.generate_dispatch( - cls, # type: ignore - cls._traverse_internals, # type: ignore + cls, + cls._traverse_internals, "_generated_copy_internals_traversal", ) _get_children.generate_dispatch( - cls, # type: ignore - cls._traverse_internals, # type: ignore + cls, + cls._traverse_internals, "_generated_get_children_traversal", ) diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py index 2be397288e..f839cf57d8 100644 --- a/lib/sqlalchemy/sql/type_api.py +++ b/lib/sqlalchemy/sql/type_api.py @@ -191,7 +191,7 @@ class TypeEngine(Visitable, Generic[_T]): op_fn, addtl_kw = default_comparator.operator_lookup[op.__name__] if kwargs: addtl_kw = addtl_kw.union(kwargs) - return op_fn(self.expr, op, *other, **addtl_kw) # type: ignore + return op_fn(self.expr, op, *other, **addtl_kw) @util.preload_module("sqlalchemy.sql.default_comparator") def reverse_operate( @@ -201,7 +201,7 @@ class TypeEngine(Visitable, Generic[_T]): op_fn, addtl_kw = default_comparator.operator_lookup[op.__name__] if kwargs: addtl_kw = addtl_kw.union(kwargs) - return op_fn(self.expr, op, other, reverse=True, **addtl_kw) # type: ignore # noqa: E501 + return op_fn(self.expr, op, other, reverse=True, **addtl_kw) def _adapt_expression( self, @@ -816,7 +816,7 @@ class TypeEngine(Visitable, Generic[_T]): best_uppercase = None if not isinstance(self, TypeEngine): - return self.__class__ # type: ignore # mypy bug? + return self.__class__ for t in self.__class__.__mro__: if ( @@ -2323,7 +2323,7 @@ def to_instance( return NULLTYPE if callable(typeobj): - return typeobj(*arg, **kw) # type: ignore # for pyright + return typeobj(*arg, **kw) else: return typeobj diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 0a50197a0d..28480a5d43 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -1440,7 +1440,7 @@ def _offset_or_limit_clause_asint_if_possible( if clause is None: return None if hasattr(clause, "_limit_offset_value"): - value = clause._limit_offset_value # type: ignore + value = clause._limit_offset_value return util.asint(value) else: return clause @@ -1489,13 +1489,11 @@ def _make_slice( offset_clause = 0 if start != 0: - offset_clause = offset_clause + start # type: ignore + offset_clause = offset_clause + start if offset_clause == 0: offset_clause = None else: - offset_clause = _offset_or_limit_clause( - offset_clause # type: ignore - ) + offset_clause = _offset_or_limit_clause(offset_clause) - return limit_clause, offset_clause # type: ignore + return limit_clause, offset_clause diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 2e793e862b..c3f3c2b9f8 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -189,7 +189,7 @@ class Properties(Generic[_T]): return dir(super()) + [str(k) for k in self._data.keys()] def __add__(self, other: Properties[_F]) -> List[Union[_T, _F]]: - return list(self) + list(other) # type: ignore + return list(self) + list(other) def __setitem__(self, key: str, obj: _T) -> None: self._data[key] = obj @@ -393,16 +393,16 @@ class UniqueAppender(Generic[_T]): self.data = data self._unique = {} if via: - self._data_appender = getattr(data, via) # type: ignore[assignment] # noqa: E501 + self._data_appender = getattr(data, via) elif hasattr(data, "append"): - self._data_appender = cast("List[_T]", data).append # type: ignore[assignment] # noqa: E501 + self._data_appender = cast("List[_T]", data).append elif hasattr(data, "add"): - self._data_appender = cast("Set[_T]", data).add # type: ignore[assignment] # noqa: E501 + self._data_appender = cast("Set[_T]", data).add def append(self, item: _T) -> None: id_ = id(item) if id_ not in self._unique: - self._data_appender(item) # type: ignore[call-arg] + self._data_appender(item) self._unique[id_] = True def __iter__(self) -> Iterator[_T]: @@ -677,7 +677,7 @@ class ThreadLocalRegistry(ScopedRegistry[_T]): return self.registry.value # type: ignore[no-any-return] except AttributeError: val = self.registry.value = self.createfunc() - return val # type: ignore[no-any-return] + return val def has(self) -> bool: return hasattr(self.registry, "value") diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py index 2b6ae8750a..71d10a6857 100644 --- a/lib/sqlalchemy/util/_concurrency_py3k.py +++ b/lib/sqlalchemy/util/_concurrency_py3k.py @@ -69,7 +69,7 @@ def is_exit_exception(e: BaseException) -> bool: # Issue for context: https://github.com/python-greenlet/greenlet/issues/173 -class _AsyncIoGreenlet(greenlet): # type: ignore +class _AsyncIoGreenlet(greenlet): dead: bool def __init__(self, fn: Callable[..., Any], driver: greenlet): @@ -147,7 +147,7 @@ def await_fallback(awaitable: Awaitable[_T]) -> _T: "loop is already running; can't call await_fallback() here. " "Was IO attempted in an unexpected place?" ) - return loop.run_until_complete(awaitable) # type: ignore[no-any-return] # noqa: E501 + return loop.run_until_complete(awaitable) return current.driver.switch(awaitable) # type: ignore[no-any-return] diff --git a/lib/sqlalchemy/util/_py_collections.py b/lib/sqlalchemy/util/_py_collections.py index 9962493b5c..4f52d3bce6 100644 --- a/lib/sqlalchemy/util/_py_collections.py +++ b/lib/sqlalchemy/util/_py_collections.py @@ -227,11 +227,11 @@ class OrderedSet(Set[_T]): super().add(e) def __ior__(self, other: AbstractSet[_S]) -> OrderedSet[Union[_T, _S]]: - self.update(other) # type: ignore - return self # type: ignore + self.update(other) + return self def union(self, *other: Iterable[_S]) -> OrderedSet[Union[_T, _S]]: - result: OrderedSet[Union[_T, _S]] = self.copy() # type: ignore + result: OrderedSet[Union[_T, _S]] = self.copy() result.update(*other) return result diff --git a/lib/sqlalchemy/util/deprecations.py b/lib/sqlalchemy/util/deprecations.py index dd5851cb3c..26d9924898 100644 --- a/lib/sqlalchemy/util/deprecations.py +++ b/lib/sqlalchemy/util/deprecations.py @@ -246,7 +246,7 @@ def deprecated_params(**specs: Tuple[str, str]) -> Callable[[_F], _F]: # latest mypy has opinions here, not sure if they implemented # Concatenate or something - @decorator # type: ignore + @decorator def warned(fn: _F, *args: Any, **kwargs: Any) -> _F: for m in check_defaults: if (defaults[m] is None and kwargs[m] is not None) or ( @@ -290,9 +290,9 @@ def deprecated_params(**specs: Tuple[str, str]) -> Callable[[_F], _F]: for param, (version, message) in specs.items() }, ) - decorated = warned(fn) # type: ignore + decorated = warned(fn) decorated.__doc__ = doc - return decorated # type: ignore[no-any-return] + return decorated return decorate @@ -334,7 +334,7 @@ def _decorate_cls_with_warning( clsdict["__doc__"] = doc clsdict.pop("__dict__", None) clsdict.pop("__weakref__", None) - cls = type(cls.__name__, cls.__bases__, clsdict) # type: ignore + cls = type(cls.__name__, cls.__bases__, clsdict) if constructor is not None: constructor_fn = clsdict[constructor] @@ -376,7 +376,7 @@ def _decorate_with_warning( else: doc_only = "" - @decorator # type: ignore + @decorator def warned(fn: _F, *args: Any, **kwargs: Any) -> _F: skip_warning = not enable_warnings or kwargs.pop( "_sa_skip_warning", False @@ -393,9 +393,9 @@ def _decorate_with_warning( doc = inject_docstring_text(doc, docstring_header, 1) - decorated = warned(func) # type: ignore + decorated = warned(func) decorated.__doc__ = doc decorated._sa_warn = lambda: _warn_with_version( # type: ignore message, version, wtype, stacklevel=3 ) - return decorated # type: ignore[no-any-return] + return decorated diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 6c9afb5df6..33d617e80c 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -526,12 +526,10 @@ def get_callable_argspec( fn.__init__, no_self=no_self, _is_init=True ) elif hasattr(fn, "__func__"): - return compat.inspect_getfullargspec(fn.__func__) # type: ignore[attr-defined] # noqa: E501 + return compat.inspect_getfullargspec(fn.__func__) elif hasattr(fn, "__call__"): - if inspect.ismethod(fn.__call__): # type: ignore [operator] - return get_callable_argspec( - fn.__call__, no_self=no_self # type: ignore [operator] - ) + if inspect.ismethod(fn.__call__): + return get_callable_argspec(fn.__call__, no_self=no_self) else: raise TypeError("Can't inspect callable: %s" % fn) else: @@ -1082,7 +1080,7 @@ class generic_fn_descriptor(Generic[_T_co]): __name__: str def __init__(self, fget: Callable[..., _T_co], doc: Optional[str] = None): - self.fget = fget # type: ignore[assignment] + self.fget = fget self.__doc__ = doc or fget.__doc__ self.__name__ = fget.__name__ @@ -1237,12 +1235,11 @@ class HasMemoized: __name__: str def __init__(self, fget: Callable[..., _T], doc: Optional[str] = None): - # https://github.com/python/mypy/issues/708 - self.fget = fget # type: ignore + self.fget = fget self.__doc__ = doc or fget.__doc__ self.__name__ = fget.__name__ - @overload # type: ignore[override] + @overload def __get__(self: _MA, obj: None, cls: Any) -> _MA: ... @@ -1476,7 +1473,7 @@ def assert_arg_type( if isinstance(argtype, tuple): raise exc.ArgumentError( "Argument '%s' is expected to be one of type %s, got '%s'" - % (name, " or ".join("'%s'" % a for a in argtype), type(arg)) # type: ignore # noqa: E501 + % (name, " or ".join("'%s'" % a for a in argtype), type(arg)) ) else: raise exc.ArgumentError( @@ -1527,7 +1524,7 @@ class classproperty(property): self.__doc__ = fget.__doc__ def __get__(self, obj: Any, cls: Optional[type] = None) -> Any: - return self.fget(cls) # type: ignore + return self.fget(cls) class hybridproperty(Generic[_T]): diff --git a/pyproject.toml b/pyproject.toml index 6e2a97d20b..3cdf49301f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,14 +66,13 @@ mypy_path = "./lib/" show_error_codes = true incremental = true - [[tool.mypy.overrides]] module = [ "sqlalchemy.*" ] -warn_unused_ignores = false +warn_unused_ignores = true strict = true diff --git a/test/typing/plain_files/orm/mapped_assign_expression.py b/test/typing/plain_files/orm/mapped_assign_expression.py index e68b4b44a7..f6289d1934 100644 --- a/test/typing/plain_files/orm/mapped_assign_expression.py +++ b/test/typing/plain_files/orm/mapped_assign_expression.py @@ -2,10 +2,10 @@ from datetime import datetime from sqlalchemy import create_engine from sqlalchemy.orm import Mapped +from sqlalchemy.orm import mapped_column from sqlalchemy.orm import registry from sqlalchemy.orm import Session from sqlalchemy.sql.functions import now -from sqlalchemy.testing.schema import mapped_column mapper_registry: registry = registry() e = create_engine("sqlite:///database.db", echo=True)