From aab70e9fb05b6c6db726b445badbde6d9d4c69f5 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Fri, 29 Aug 2025 12:43:28 +0200 Subject: [PATCH] Use cached_property from the stdlib Our local implementation preceded the one in the stdlib, but we no longer support versions of Python which do not ship it. --- vdirsyncer/cli/config.py | 2 +- vdirsyncer/storage/dav.py | 3 ++- vdirsyncer/utils.py | 18 ------------------ vdirsyncer/vobject.py | 2 +- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index ba48faf..5098efd 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -4,6 +4,7 @@ import json import os import string from configparser import RawConfigParser +from functools import cached_property from itertools import chain from typing import IO from typing import Any @@ -11,7 +12,6 @@ from typing import Generator from vdirsyncer import PROJECT_HOME from vdirsyncer import exceptions -from vdirsyncer.utils import cached_property from vdirsyncer.utils import expand_path from vdirsyncer.vobject import Item diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py index 6aee4cb..9402617 100644 --- a/vdirsyncer/storage/dav.py +++ b/vdirsyncer/storage/dav.py @@ -6,6 +6,7 @@ import logging import urllib.parse as urlparse import xml.etree.ElementTree as etree from abc import abstractmethod +from functools import cached_property from inspect import getfullargspec from inspect import signature @@ -390,7 +391,7 @@ class DAVSession: self.url = url.rstrip("/") + "/" self.connector = connector - @utils.cached_property + @cached_property def parsed_url(self): return urlparse.urlparse(self.url) diff --git a/vdirsyncer/utils.py b/vdirsyncer/utils.py index 62685b8..1a62ab0 100644 --- a/vdirsyncer/utils.py +++ b/vdirsyncer/utils.py @@ -145,24 +145,6 @@ def checkfile(path, create=False) -> None: raise exceptions.CollectionNotFound(f"File {path} does not exist.") -class cached_property: - """A read-only @property that is only evaluated once. Only usable on class - instances' methods. - """ - - def __init__(self, fget, doc=None): - self.__name__ = fget.__name__ - self.__module__ = fget.__module__ - self.__doc__ = doc or fget.__doc__ - self.fget = fget - - def __get__(self, obj, cls): - if obj is None: # pragma: no cover - return self - obj.__dict__[self.__name__] = result = self.fget(obj) - return result - - def href_safe(ident, safe=SAFE_UID_CHARS): return not bool(set(ident) - set(safe)) diff --git a/vdirsyncer/vobject.py b/vdirsyncer/vobject.py index 08d0522..c609cd0 100644 --- a/vdirsyncer/vobject.py +++ b/vdirsyncer/vobject.py @@ -1,10 +1,10 @@ from __future__ import annotations import hashlib +from functools import cached_property from itertools import chain from itertools import tee -from .utils import cached_property from .utils import uniq IGNORE_PROPS = (