Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/interface.py
Show All 26 Lines | |||||
) | ) | ||||
def deprecated(f): | def deprecated(f): | ||||
f.deprecated_endpoint = True | f.deprecated_endpoint = True | ||||
return f | return f | ||||
class StorageInterface: | class StorageInterface: | ||||
vlorentz: PagedResult is not an instance of `CorePagedResult[TResult, str]`, it's `CorePagedResult… | |||||
Done Inline ActionsI tried that as well... swh/storage/interface.py:36: error: Type variable "swh.core.api.classes.TResult" is unbound swh/storage/interface.py:36: note: (Hint: Use "Generic[TResult]" or "Protocol[TResult]" base class to bind "TResult" inside a class) swh/storage/interface.py:36: note: (Hint: Use "TResult" in function signature to bind "TResult" inside a function) swh/storage/interface.py:810: error: Variable "swh.storage.interface.PagedResult" is not valid as a type swh/storage/interface.py:810: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases swh/storage/in_memory.py:869: error: Variable "swh.storage.interface.PagedResult" is not valid as a type swh/storage/in_memory.py:869: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases swh/storage/cassandra/storage.py:851: error: Variable "swh.storage.interface.PagedResult" is not valid as a type swh/storage/cassandra/storage.py:851: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases swh/storage/storage.py:890: error: Variable "swh.storage.interface.PagedResult" is not valid as a type swh/storage/storage.py:890: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases Found 5 errors in 4 files (checked 68 source files) ardumont: I tried that as well...
```
swh/storage/interface.py:36: error: Type variable "swh.core.api. | |||||
Done Inline Actionsah yes, that makes sense. vlorentz: ah yes, that makes sense. | |||||
@remote_api_endpoint("check_config") | @remote_api_endpoint("check_config") | ||||
def check_config(self, *, check_write): | def check_config(self, *, check_write): | ||||
"""Check that the storage is configured and ready to go.""" | """Check that the storage is configured and ready to go.""" | ||||
... | ... | ||||
Done Inline Actionsif you want this one to work, don't reuse the same TypeVar: TResult = TypeVar("TResult") class PagedResult(CorePagedResult[TResult, str]): pass vlorentz: if you want this one to work, don't reuse the same TypeVar:
```
TResult = TypeVar("TResult")… | |||||
Done Inline Actions
why? I recall having tested that (without redefining TResult though) that would not work... ardumont: > if you want this one to work, don't reuse the same TypeVar:
why?
----
I recall having… | |||||
Done Inline ActionsI'm guessing it makes mypy glitchy to use the same typevar in both a generic class in a subclass of that class vlorentz: I'm guessing it makes mypy glitchy to use the same typevar in both a generic class in a… | |||||
@remote_api_endpoint("content/add") | @remote_api_endpoint("content/add") | ||||
def content_add(self, content: Iterable[Content]) -> Dict: | def content_add(self, content: Iterable[Content]) -> Dict: | ||||
"""Add content blobs to the storage | """Add content blobs to the storage | ||||
Args: | Args: | ||||
contents (iterable): iterable of dictionaries representing | contents (iterable): iterable of dictionaries representing | ||||
individual pieces of content to add. Each dictionary has the | individual pieces of content to add. Each dictionary has the | ||||
following keys: | following keys: | ||||
▲ Show 20 Lines • Show All 739 Lines • ▼ Show 20 Lines | ) -> None: | ||||
""" | """ | ||||
... | ... | ||||
@remote_api_endpoint("origin/visit/get") | @remote_api_endpoint("origin/visit/get") | ||||
def origin_visit_get( | def origin_visit_get( | ||||
self, | self, | ||||
origin: str, | origin: str, | ||||
last_visit: Optional[int] = None, | page_token: Optional[str] = None, | ||||
limit: Optional[int] = None, | |||||
order: str = "asc", | order: str = "asc", | ||||
) -> Iterable[Dict[str, Any]]: | limit: int = 10, | ||||
"""Retrieve all the origin's visit's information. | ) -> Dict[str, Any]: | ||||
"""Retrieve OriginVisit information. | |||||
Args: | Args: | ||||
origin: The visited origin | origin: The visited origin | ||||
last_visit: Starting point from which listing the next visits | page_token: opaque string used to get the next results of a search | ||||
Default to None | |||||
limit: Number of results to return from the last visit. | |||||
Default to None | |||||
order: Order on visit id fields to list origin visits (default to asc) | order: Order on visit id fields to list origin visits (default to asc) | ||||
limit: Number of visits to return | |||||
Yields: | Raises: | ||||
List of visits. | StorageArgumentException if wrong order or wrong page_token type | ||||
Returns: | |||||
Dict with the following keys: | |||||
- **next_page_token** (str, optional): opaque token to be used as | |||||
`page_token` for retrieving the next page. if absent, there is | |||||
no more pages to gather. | |||||
- **visits** (Iterable[OriginVisit]): list of visits | |||||
""" | """ | ||||
... | ... | ||||
# @remote_api_endpoint("origin/visit_status/get") | |||||
# def origin_visit_status_get( | |||||
# self, | |||||
# origin: str, | |||||
# last_visit: Optional[int] = None, | |||||
# limit: Optional[int] = None, | |||||
# order: str = "asc", | |||||
# ) -> Iterable[Optional[OriginVisitStatus]]: | |||||
# """Retrieve OriginVisit information. | |||||
# Args: | |||||
# origin: The visited origin | |||||
# last_visit: Starting point from which listing the next visits | |||||
# Default to None | |||||
# limit: Number of results to return from the last visit. | |||||
# Default to None | |||||
# order: Order on visit id fields to list origin visits (default to asc) | |||||
# Yields: | |||||
# List of optional (when not found) visits | |||||
# """ | |||||
# ... | |||||
@remote_api_endpoint("origin/visit/find_by_date") | @remote_api_endpoint("origin/visit/find_by_date") | ||||
def origin_visit_find_by_date( | def origin_visit_find_by_date( | ||||
self, origin: str, visit_date: datetime.datetime | self, origin: str, visit_date: datetime.datetime | ||||
) -> Optional[OriginVisit]: | ) -> Optional[OriginVisit]: | ||||
"""Retrieves the origin visit whose date is closest to the provided | """Retrieves the origin visit whose date is closest to the provided | ||||
timestamp. | timestamp. | ||||
In case of a tie, the visit with largest id is selected. | In case of a tie, the visit with largest id is selected. | ||||
▲ Show 20 Lines • Show All 435 Lines • Show Last 20 Lines |
PagedResult is not an instance of CorePagedResult[TResult, str], it's CorePagedResult[TResult, str] itself. Therefore: