Fix some mypy type failures

This commit is contained in:
Hugo Osvaldo Barrera 2025-09-20 13:51:00 +02:00
parent 6354db82c4
commit 2f4f4ac72b
8 changed files with 16 additions and 9 deletions

View file

@ -95,7 +95,7 @@ async def collections_for_pair(
# We have to use a list here because the special None/null value would get
# mangled to string (because JSON objects always have string keys).
rv = await aiostream.stream.list(
rv = await aiostream.stream.list( # type: ignore[assignment]
expand_collections(
shortcuts=pair.collections,
config_a=pair.config_a,

View file

@ -31,7 +31,7 @@ STATUS_DIR_PERMISSIONS = 0o700
class _StorageIndex:
def __init__(self):
def __init__(self) -> None:
self._storages: dict[str, str] = {
"caldav": "vdirsyncer.storage.dav.CalDAVStorage",
"carddav": "vdirsyncer.storage.dav.CardDAVStorage",

View file

@ -150,7 +150,7 @@ class Storage(metaclass=StorageMeta):
"""
@abstractmethod
async def get(self, href: str):
async def get(self, href: str) -> tuple[Item, str]:
"""Fetch a single item.
:param href: href to fetch

View file

@ -497,8 +497,12 @@ class DAVStorage(Storage):
def _is_item_mimetype(self, mimetype):
return _fuzzy_matches_mimetype(self.item_mimetype, mimetype)
async def get(self, href: str):
((actual_href, item, etag),) = await aiostream.stream.list(
async def get(self, href: str) -> tuple[Item, str]:
actual_href: str
item: Item
etag: str
((actual_href, item, etag),) = await aiostream.stream.list( # type: ignore[misc]
self.get_multi([href])
)
assert href == actual_href

View file

@ -98,7 +98,7 @@ class FilesystemStorage(Storage):
):
yield fname, get_etag_from_file(fpath)
async def get(self, href):
async def get(self, href) -> tuple[Item, str]:
fpath = self._get_filepath(href)
try:
with open(fpath, "rb") as f:

View file

@ -117,11 +117,12 @@ class HttpStorage(Storage):
for href, (_, etag) in self._items.items():
yield href, etag
async def get(self, href):
async def get(self, href) -> tuple[Item, str]:
if self._items is None:
async for _ in self.list():
pass
assert self._items is not None # type assertion
try:
return self._items[href]
except KeyError:

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import random
from vdirsyncer import exceptions
from vdirsyncer.vobject import Item
from .base import Storage
from .base import normalize_meta_value
@ -34,7 +35,7 @@ class MemoryStorage(Storage):
for href, (etag, _item) in self.items.items():
yield href, etag
async def get(self, href):
async def get(self, href) -> tuple[Item, str]:
etag, item = self.items[href]
return item, etag

View file

@ -133,11 +133,12 @@ class SingleFileStorage(Storage):
yield href, etag
async def get(self, href):
async def get(self, href) -> tuple[Item, str]:
if self._items is None or not self._at_once:
async for _ in self.list():
pass
assert self._items is not None # type assertion
try:
return self._items[href]
except KeyError: