From 8478245cdec54f1359efd2e68ae42174db56b3aa Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 24 Apr 2023 21:48:52 +0200 Subject: [PATCH] Removed `Mapped[Entity]` type annotation. `Mapped` has been introduced only in SQLAlchemy 1.4, while Debian stable still ships 1.3. Removing the type annotation doesn't come with a big cost, but it keeps Platypush compatible with Debian stable. --- platypush/entities/_base.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/platypush/entities/_base.py b/platypush/entities/_base.py index b5b4d187..5ec30cdd 100644 --- a/platypush/entities/_base.py +++ b/platypush/entities/_base.py @@ -20,7 +20,7 @@ from sqlalchemy import ( UniqueConstraint, inspect as schema_inspect, ) -from sqlalchemy.orm import ColumnProperty, Mapped, backref, relationship +from sqlalchemy.orm import ColumnProperty, backref, relationship from sqlalchemy.orm.exc import ObjectDeletedError from platypush.common.db import Base @@ -84,7 +84,7 @@ if 'entity' not in Base.metadata: onupdate=datetime.utcnow(), ) - parent: Mapped['Entity'] = relationship( + parent = relationship( 'Entity', remote_side=[id], uselist=False, @@ -131,15 +131,16 @@ if 'entity' not in Base.metadata: to reuse entity objects in other threads or outside of their associated SQLAlchemy session context. """ + def key_value_pair(col: ColumnProperty): try: return (col.key, getattr(self, col.key, None)) - except ObjectDeletedError as e: + except ObjectDeletedError: return None return self.__class__( **dict( - key_value_pair(col) + key_value_pair(col) # type: ignore for col in self.columns if key_value_pair(col) is not None ), @@ -180,7 +181,7 @@ if 'entity' not in Base.metadata: """ col_name = self._column_name(col) if col_name is None: - return tuple() + return () return col_name, self._serialize_value(col_name) def to_dict(self) -> dict: @@ -215,7 +216,7 @@ if 'entity' not in Base.metadata: """ Serializes the new value before assigning it to an attribute. """ - matching_columns = [c for c in self.columns if c.expression.name == key] + matching_columns = [c for c in self.columns if c.expression.name == key] # type: ignore if ( matching_columns @@ -275,7 +276,7 @@ def _discover_entity_types(): for _, obj in inspect.getmembers(module): if inspect.isclass(obj) and issubclass(obj, Entity): - entities_registry[obj] = {} + entities_registry[obj] = {} # type: ignore def get_entities_registry() -> EntityRegistryType: