From dd9078f2587a23ffc5ea3fbce1f1ab28e2d9db5b Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 15 May 2023 19:37:53 +0000 Subject: [PATCH] Adjust Base class to make mypy happy. --- matcher/model.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/matcher/model.py b/matcher/model.py index aac4527..6eb122b 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -9,10 +9,11 @@ from geoalchemy2 import Geometry from sqlalchemy import func from sqlalchemy.dialects import postgresql from sqlalchemy.ext.associationproxy import association_proxy -from sqlalchemy.ext.declarative import declarative_base, declared_attr +from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.hybrid import hybrid_property -from sqlalchemy.orm import backref, column_property, deferred, relationship +from sqlalchemy.orm import backref, column_property, deferred, registry, relationship from sqlalchemy.orm.collections import attribute_mapped_collection +from sqlalchemy.orm.decl_api import DeclarativeMeta from sqlalchemy.schema import Column, ForeignKey from sqlalchemy.sql.expression import cast from sqlalchemy.types import BigInteger, Boolean, DateTime, Float, Integer, String, Text @@ -20,8 +21,18 @@ from sqlalchemy.types import BigInteger, Boolean, DateTime, Float, Integer, Stri from . import mail, utils, wikidata from .database import now_utc, session -Base = declarative_base() -Base.query = session.query_property() +mapper_registry = registry() + + +class Base(metaclass=DeclarativeMeta): + __abstract__ = True + + registry = mapper_registry + metadata = mapper_registry.metadata + query = session.query_property() + + __init__ = mapper_registry.constructor + re_point = re.compile(r"^POINT\((.+) (.+)\)$")