diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index f9884d6..bbfec2c 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -257,7 +257,7 @@ class PairConfig: ): if conflict_resolution in (None, "a wins", "b wins"): return conflict_resolution - elif ( + if ( isinstance(conflict_resolution, list) and len(conflict_resolution) > 1 and conflict_resolution[0] == "command" @@ -271,8 +271,7 @@ class PairConfig: return _resolve_conflict_via_command(a, b, command, a_name, b_name) return resolve - else: - raise ValueError("Invalid value for `conflict_resolution`.") + raise ValueError("Invalid value for `conflict_resolution`.") # The following parameters are lazily evaluated because evaluating # self.config_a would expand all `x.fetch` parameters. This is costly and diff --git a/vdirsyncer/cli/discover.py b/vdirsyncer/cli/discover.py index ebd4e16..62495a7 100644 --- a/vdirsyncer/cli/discover.py +++ b/vdirsyncer/cli/discover.py @@ -59,21 +59,20 @@ async def collections_for_pair( cache_key = _get_collections_cache_key(pair) if from_cache: rv = load_status(status_path, pair.name, data_type="collections") - if rv.get("cache_key", None) == cache_key: + if rv and rv.get("cache_key", None) == cache_key: return list( _expand_collections_cache( rv["collections"], pair.config_a, pair.config_b ) ) - elif rv: + if rv: raise exceptions.UserError( "Detected change in config file, " f"please run `vdirsyncer discover {pair.name}`." ) - else: - raise exceptions.UserError( - f"Please run `vdirsyncer discover {pair.name}` before synchronization." - ) + raise exceptions.UserError( + f"Please run `vdirsyncer discover {pair.name}` before synchronization." + ) logger.info(f"Discovering collections for pair {pair.name}") diff --git a/vdirsyncer/cli/utils.py b/vdirsyncer/cli/utils.py index 37c27c4..8fa51ee 100644 --- a/vdirsyncer/cli/utils.py +++ b/vdirsyncer/cli/utils.py @@ -294,8 +294,7 @@ async def storage_instance_from_config( create=False, connector=connector, ) - else: - raise + raise except Exception: return handle_storage_init_error(cls, new_config) diff --git a/vdirsyncer/http.py b/vdirsyncer/http.py index 51d451c..0ecd6d2 100644 --- a/vdirsyncer/http.py +++ b/vdirsyncer/http.py @@ -100,9 +100,9 @@ def prepare_auth(auth, username, password): if username and password: if auth == "basic" or auth is None: return BasicAuthMethod(username, password) - elif auth == "digest": + if auth == "digest": return DigestAuthMethod(username, password) - elif auth == "guess": + if auth == "guess": raise exceptions.UserError( "'Guess' authentication is not supported in this version of vdirsyncer. \n" "Please explicitly specify either 'basic' or 'digest' auth instead. \n" diff --git a/vdirsyncer/storage/dav.py b/vdirsyncer/storage/dav.py index b911082..6546322 100644 --- a/vdirsyncer/storage/dav.py +++ b/vdirsyncer/storage/dav.py @@ -114,9 +114,7 @@ def _fuzzy_matches_mimetype(strict, weak): return True mediatype, subtype = strict.split("/") - if subtype in weak: - return True - return False + return subtype in weak class Discover: @@ -237,7 +235,7 @@ class Discover: return True props = _merge_xml(response.findall("{DAV:}propstat/{DAV:}prop")) - if props is None or not len(props): + if props is None or not props: dav_logger.debug("Skipping, missing : %s", response) return False if props.find("{DAV:}resourcetype/" + self._resourcetype) is None: @@ -626,7 +624,7 @@ class DAVStorage(Storage): continue props = response.findall("{DAV:}propstat/{DAV:}prop") - if props is None or not len(props): + if props is None or not props: dav_logger.debug(f"Skipping {href!r}, properties are missing.") continue else: diff --git a/vdirsyncer/utils.py b/vdirsyncer/utils.py index f5a5581..2d4b5f2 100644 --- a/vdirsyncer/utils.py +++ b/vdirsyncer/utils.py @@ -24,8 +24,7 @@ _missing = object() def expand_path(p: str) -> str: """Expand $HOME in a path and normalise slashes.""" p = os.path.expanduser(p) - p = os.path.normpath(p) - return p + return os.path.normpath(p) def split_dict(d: dict, f: Callable): @@ -177,8 +176,7 @@ def generate_href(ident=None, safe=SAFE_UID_CHARS): """ if not ident or not href_safe(ident, safe): return str(uuid.uuid4()) - else: - return ident + return ident def synchronized(lock=None): diff --git a/vdirsyncer/vobject.py b/vdirsyncer/vobject.py index 8fdb2ab..08d0522 100644 --- a/vdirsyncer/vobject.py +++ b/vdirsyncer/vobject.py @@ -231,8 +231,7 @@ def _get_item_type(components, wrappers): if not i: return None, None - else: - raise ValueError("Not sure how to join components.") + raise ValueError("Not sure how to join components.") class _Component: @@ -303,10 +302,9 @@ class _Component: if multiple: return rv - elif len(rv) != 1: + if len(rv) != 1: raise ValueError(f"Found {len(rv)} components, expected one.") - else: - return rv[0] + return rv[0] def dump_lines(self): yield f"BEGIN:{self.name}" @@ -323,8 +321,7 @@ class _Component: for line in lineiter: if line.startswith(prefix): break - else: - new_lines.append(line) + new_lines.append(line) else: break @@ -347,10 +344,9 @@ class _Component: return obj not in self.subcomponents and not any( obj in x for x in self.subcomponents ) - elif isinstance(obj, str): + if isinstance(obj, str): return self.get(obj, None) is not None - else: - raise ValueError(obj) + raise ValueError(obj) def __getitem__(self, key): prefix_without_params = f"{key}:" @@ -360,7 +356,7 @@ class _Component: if line.startswith(prefix_without_params): rv = line[len(prefix_without_params) :] break - elif line.startswith(prefix_with_params): + if line.startswith(prefix_with_params): rv = line[len(prefix_with_params) :].split(":", 1)[-1] break else: