Skip to content

Commit

Permalink
Fix type signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
lucc committed Sep 7, 2023
1 parent 1f2f386 commit 5718d96
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions khard/carddav_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

from . import address_book # pylint: disable=unused-import # for type checking
from . import helpers
from .helpers.typing import (convert_to_vcard, Date, ObjectType, StrList,
list_to_string, string_to_date, string_to_list)
from .helpers.typing import (Date, ObjectType, PostAddress, StrList,
convert_to_vcard, list_to_string, string_to_date, string_to_list)
from .query import AnyQuery, Query


Expand Down Expand Up @@ -770,11 +770,11 @@ def add_email(self, type: str, address: str) -> None:
label_obj.value = custom_types[0]

@property
def post_addresses(self) -> Dict[str, List[Dict[str, Union[List, str]]]]:
def post_addresses(self) -> Dict[str, List[PostAddress]]:
"""
:returns: dict of type and post address list
"""
post_adr_dict: Dict[str, List[Dict[str, Union[List, str]]]] = {}
post_adr_dict: Dict[str, List[PostAddress]] = {}
for child in self.vcard.getChildren():
if child.name == "ADR":
type = list_to_string(self._get_types_for_vcard_object(
Expand Down
16 changes: 10 additions & 6 deletions khard/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from typing import Any, Dict, List, Optional, Sequence, Union

from ruamel.yaml.scalarstring import LiteralScalarString
from .typing import list_to_string
from .typing import list_to_string, PostAddress


YamlPostAddresses = Dict[str, Union[List[Dict[str, Any]], Dict[str, Any]]]


def pretty_print(table: List[List[str]], justify: str = "L") -> str:
Expand Down Expand Up @@ -115,10 +118,10 @@ def yaml_dicts(
return data_dict


def yaml_addresses(addresses: Optional[Dict[str, List]],
def yaml_addresses(addresses: Optional[Dict[str, List[PostAddress]]],
address_properties: List[str],
defaults: Optional[List[str]] = None
) -> Optional[Dict[str, Any]]:
) -> Optional[YamlPostAddresses]:
"""
build a dict from an address, using a list of properties, an address has.
Expand All @@ -134,16 +137,17 @@ def yaml_addresses(addresses: Optional[Dict[str, List]],
address_fields = {key: None for key in address_properties}
return {address_type: address_fields for address_type in defaults}

address_dict = {}
address_dict: YamlPostAddresses = {}
for address_type, addresses_ in addresses.items():
entry = [
{key: yaml_clean(address.get(f"{key[0].lower()}{key[1:]}"))
for key in address_properties}
for address in addresses_
]
if len(entry) == 1:
entry = entry[0]
address_dict[address_type] = entry
address_dict[address_type] = entry[0]
else:
address_dict[address_type] = entry
return address_dict


Expand Down
3 changes: 2 additions & 1 deletion khard/helpers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from datetime import datetime
from enum import Enum
from typing import List, Union
from typing import Dict, List, Union


class ObjectType(Enum):
Expand All @@ -14,6 +14,7 @@ class ObjectType(Enum):
# some type aliases
Date = Union[str, datetime]
StrList = Union[str, List[str]]
PostAddress = Dict[str, str]


def convert_to_vcard(name: str, value: StrList, constraint: ObjectType
Expand Down

0 comments on commit 5718d96

Please sign in to comment.