Skip to content

Commit

Permalink
Define overloaded methods for typing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber committed Mar 9, 2022
1 parent d005cfe commit 5400aee
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion aiida/orm/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
An instance of one of the implementation classes becomes a member of the :func:`QueryBuilder` instance
when instantiated by the user.
"""
from __future__ import annotations

from copy import deepcopy
from inspect import isclass as inspect_isclass
from typing import (
Expand All @@ -27,6 +29,7 @@
Dict,
Iterable,
List,
Literal,
NamedTuple,
Optional,
Sequence,
Expand All @@ -35,6 +38,7 @@
Type,
Union,
cast,
overload,
)
import warnings

Expand Down Expand Up @@ -989,7 +993,15 @@ def _get_aiida_entity_res(value) -> Any:
except TypeError:
return value

def first(self, flat: bool = False) -> Optional[Union[List[Any], Any]]:
@overload
def first(self, flat: Literal[False]) -> Optional[list[Any]]:
...

@overload
def first(self, flat: Literal[True]) -> Optional[Any]:
...

def first(self, flat: bool = False) -> Optional[list[Any] | Any]:
"""Return the first result of the query.
Calling ``first`` results in an execution of the underlying query.
Expand Down

0 comments on commit 5400aee

Please sign in to comment.