rewrite: Fix ORM typing issues.

This commit is contained in:
2022-11-11 08:03:13 +02:00
parent 3445bdff3e
commit 2121749238
5 changed files with 14 additions and 10 deletions

View File

@@ -20,7 +20,10 @@ class RegisterEnum(Attachable):
return self return self
async def on_init(self, registry: Registry): async def on_init(self, registry: Registry):
connection = await registry._conn.get_connection() connector = registry._conn
if connector is None:
raise ValueError("Cannot initialise without connector!")
connection = await connector.get_connection()
if connection is None: if connection is None:
raise ValueError("Cannot Init without connection.") raise ValueError("Cannot Init without connection.")
info = await EnumInfo.fetch(connection, self.name) info = await EnumInfo.fetch(connection, self.name)

View File

@@ -103,9 +103,9 @@ if TYPE_CHECKING:
class Column(ColumnExpr, Generic[T]): class Column(ColumnExpr, Generic[T]):
def __init__(self, name: str = None, primary: bool = False): def __init__(self, name: str = None, primary: bool = False): # type: ignore
self.primary = primary self.primary = primary
self.name: str = name # type: ignore self.name: str = name
self.expr = sql.Identifier(name) if name else sql.SQL('') self.expr = sql.Identifier(name) if name else sql.SQL('')
self.values = () self.values = ()

View File

@@ -131,7 +131,7 @@ class RowModel:
# TODO: Proper typing for a classvariable which gets dynamically assigned in subclass # TODO: Proper typing for a classvariable which gets dynamically assigned in subclass
table: RowTable table: RowTable
def __init_subclass__(cls: Type[RowT], table: str = None): def __init_subclass__(cls: Type[RowT], table: Optional[str] = None):
""" """
Set table, _columns_, and _key_. Set table, _columns_, and _key_.
""" """

View File

@@ -169,11 +169,11 @@ class JoinMixin(TableQuery[QueryResult]):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._joins: list[Expression, ...] = [] self._joins: list[Expression] = []
def join(self, def join(self,
target: Union[str, Expression], target: Union[str, Expression],
on: Optional[Condition] = None, using: Union[Expression, tuple[str, ...]] = None, on: Optional[Condition] = None, using: Optional[Union[Expression, tuple[str, ...]]] = None,
natural=False): natural=False):
available = (on is not None) + (using is not None) + natural available = (on is not None) + (using is not None) + natural
if available == 0: if available == 0:
@@ -304,9 +304,10 @@ class OrderMixin(TableQuery[QueryResult]):
@property @property
def _order_section(self) -> Optional[Expression]: def _order_section(self) -> Optional[Expression]:
if self._order is not None: if self._order:
expr = RawExpr.join(*self._order, joiner=sql.SQL(', ')) expr = RawExpr.join(*self._order, joiner=sql.SQL(', '))
expr.expr = sql.SQL("ORDER BY {}").formt(expr.expr) expr.expr = sql.SQL("ORDER BY {}").format(expr.expr)
return expr
else: else:
return None return None

View File

@@ -24,8 +24,8 @@ class Registry:
cls._name = name or cls.__name__ cls._name = name or cls.__name__
def __init__(self, name=None): def __init__(self, name=None):
self._conn: Connector = None self._conn: Optional[Connector] = None
self.name: str = name or self._name self.name: str = name if name is not None else self._name
if self.name is None: if self.name is None:
raise ValueError("A Registry must have a name!") raise ValueError("A Registry must have a name!")