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 # 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). # 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( expand_collections(
shortcuts=pair.collections, shortcuts=pair.collections,
config_a=pair.config_a, config_a=pair.config_a,

View file

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

View file

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

View file

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

View file

@ -98,7 +98,7 @@ class FilesystemStorage(Storage):
): ):
yield fname, get_etag_from_file(fpath) 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) fpath = self._get_filepath(href)
try: try:
with open(fpath, "rb") as f: with open(fpath, "rb") as f:

View file

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

View file

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

View file

@ -133,11 +133,12 @@ class SingleFileStorage(Storage):
yield href, etag 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: if self._items is None or not self._at_once:
async for _ in self.list(): async for _ in self.list():
pass pass
assert self._items is not None # type assertion
try: try:
return self._items[href] return self._items[href]
except KeyError: except KeyError: