diff --git a/caramel/models.py b/caramel/models.py index 83d7071..e9f3752 100644 --- a/caramel/models.py +++ b/caramel/models.py @@ -3,8 +3,8 @@ import sqlalchemy as _sa from sqlalchemy.ext.declarative import ( - declarative_base as _declarative_base, - declared_attr as _declared_attr, + declared_attr, + as_declarative ) import sqlalchemy.orm as _orm from zope.sqlalchemy import register @@ -14,7 +14,7 @@ import datetime as _datetime import dateutil.parser import uuid - +from typing import List X509_V3 = 0x2 # RFC 2459, 4.1.2.1 @@ -88,10 +88,11 @@ def _fkcolumn(referent, *args, **kwargs): register(DBSession) +@as_declarative() class Base(object): - @_declared_attr - def __tablename__(cls): - return cls.__name__.lower() + @declared_attr # type: ignore + def __tablename__(cls) -> str: + return cls.__name__.lower() # pylint: disable=no-member id = _sa.Column(_sa.Integer, primary_key=True) @@ -108,10 +109,6 @@ def all(cls): return cls.query().all() -# XXX: Newer versions of sqlalchemy have a decorator variant 'as_declarative' -Base = _declarative_base(cls=Base) - - # XXX: not the best of names def init_session(engine, create=False): DBSession.configure(bind=engine) @@ -135,10 +132,10 @@ class CSR(Base): orgunit = _sa.Column(_sa.String(_UB_OU_LEN)) commonname = _sa.Column(_sa.String(_UB_CN_LEN)) rejected = _sa.Column(_sa.Boolean(create_constraint=True)) - accessed = _orm.relationship( + accessed: List["AccessLog"] = _orm.relationship( "AccessLog", backref="csr", order_by="AccessLog.when.desc()" ) - certificates = _orm.relationship( + certificates: List["Certificate"] = _orm.relationship( "Certificate", backref="csr", order_by="Certificate.not_after.desc()",