Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👌 IMPROVE: Add typing to QueryBuilder #5063

Merged
merged 8 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ repos:
aiida/engine/.*py|
aiida/manage/manager.py|
aiida/manage/database/delete/nodes.py|
aiida/orm/querybuilder.py|
aiida/orm/nodes/data/jsonable.py|
aiida/orm/nodes/node.py|
aiida/orm/nodes/process/.*py|
Expand Down
93 changes: 29 additions & 64 deletions aiida/orm/implementation/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
###########################################################################
"""Generic backend related objects"""
import abc
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from sqlalchemy.orm.session import Session

from aiida.orm.implementation import (
BackendAuthInfoCollection, BackendCommentCollection, BackendComputerCollection, BackendGroupCollection,
BackendLogCollection, BackendNodeCollection, BackendQueryBuilder, BackendUserCollection
)
from aiida.backends.general.abstractqueries import AbstractQueryManager

__all__ = ('Backend',)

Expand All @@ -21,85 +31,40 @@ def migrate(self):
"""Migrate the database to the latest schema generation or version."""

@abc.abstractproperty
def authinfos(self):
"""
Return the collection of authorisation information objects

:return: the authinfo collection
:rtype: :class:`aiida.orm.implementation.BackendAuthInfoCollection`
"""
def authinfos(self) -> 'BackendAuthInfoCollection':
"""Return the collection of authorisation information objects"""

@abc.abstractproperty
def comments(self):
"""
Return the collection of comments

:return: the comment collection
:rtype: :class:`aiida.orm.implementation.BackendCommentCollection`
"""
def comments(self) -> 'BackendCommentCollection':
"""Return the collection of comments"""

@abc.abstractproperty
def computers(self):
"""
Return the collection of computers

:return: the computers collection
:rtype: :class:`aiida.orm.implementation.BackendComputerCollection`
"""
def computers(self) -> 'BackendComputerCollection':
"""Return the collection of computers"""

@abc.abstractproperty
def groups(self):
"""
Return the collection of groups

:return: the groups collection
:rtype: :class:`aiida.orm.implementation.BackendGroupCollection`
"""
def groups(self) -> 'BackendGroupCollection':
"""Return the collection of groups"""

@abc.abstractproperty
def logs(self):
"""
Return the collection of logs

:return: the log collection
:rtype: :class:`aiida.orm.implementation.BackendLogCollection`
"""
def logs(self) -> 'BackendLogCollection':
"""Return the collection of logs"""

@abc.abstractproperty
def nodes(self):
"""
Return the collection of nodes

:return: the nodes collection
:rtype: :class:`aiida.orm.implementation.BackendNodeCollection`
"""
def nodes(self) -> 'BackendNodeCollection':
"""Return the collection of nodes"""

@abc.abstractproperty
def query_manager(self):
"""
Return the query manager for the objects stored in the backend

:return: The query manger
:rtype: :class:`aiida.backends.general.abstractqueries.AbstractQueryManager`
"""
def query_manager(self) -> 'AbstractQueryManager':
"""Return the query manager for the objects stored in the backend"""

@abc.abstractmethod
def query(self):
"""
Return an instance of a query builder implementation for this backend

:return: a new query builder instance
:rtype: :class:`aiida.orm.implementation.BackendQueryBuilder`
"""
def query(self) -> 'BackendQueryBuilder':
"""Return an instance of a query builder implementation for this backend"""

@abc.abstractproperty
def users(self):
"""
Return the collection of users

:return: the users collection
:rtype: :class:`aiida.orm.implementation.BackendUserCollection`
"""
def users(self) -> 'BackendUserCollection':
"""Return the collection of users"""

@abc.abstractmethod
def transaction(self):
Expand All @@ -112,7 +77,7 @@ def transaction(self):
"""

@abc.abstractmethod
def get_session(self):
def get_session(self) -> 'Session':
"""Return a database session that can be used by the `QueryBuilder` to perform its query.

:return: an instance of :class:`sqlalchemy.orm.session.Session`
Expand Down
6 changes: 5 additions & 1 deletion aiida/orm/implementation/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
likely be moved to a `SqlAlchemyBasedQueryBuilder` class and restore this abstract class to being a pure agnostic one.
"""
import abc
from typing import TYPE_CHECKING
import uuid

# pylint: disable=no-name-in-module,import-error
Expand All @@ -25,6 +26,9 @@

from aiida.common.lang import type_check

if TYPE_CHECKING:
from sqlalchemy.orm.session import Session # pylint: disable=ungrouped-imports

__all__ = ('BackendQueryBuilder',)


Expand Down Expand Up @@ -111,7 +115,7 @@ def AiidaNode(self):
from aiida.orm import Node
return Node

def get_session(self):
def get_session(self) -> 'Session':
"""
:returns: a valid session, an instance of :class:`sqlalchemy.orm.session.Session`
"""
Expand Down
Loading