Skip to content

Commit 6d1310c

Browse files
committed
Use new type annotation features from python 3.9
1 parent b864931 commit 6d1310c

File tree

12 files changed

+200
-193
lines changed

12 files changed

+200
-193
lines changed

khard/actions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""Names and aliases for the subcommands on the command line"""
22

3-
from typing import Dict, Generator, Iterable, List, Optional
3+
from __future__ import annotations
4+
5+
from typing import Generator, Iterable
46

57

68
class Actions:
79

810
"""A class to manage the names and aliases of the command line
911
subcommands."""
1012

11-
action_map: Dict[str, List[str]] = {
13+
action_map: dict[str, list[str]] = {
1214
"add-email": [],
1315
"addressbooks": ["abooks"],
1416
"birthdays": ["bdays"],
@@ -28,7 +30,7 @@ class Actions:
2830
}
2931

3032
@classmethod
31-
def get_action(cls, alias: str) -> Optional[str]:
33+
def get_action(cls, alias: str) -> None | str:
3234
"""Find the name of the action for the supplied alias. If no action is
3335
associated with the given alias, None is returned.
3436
@@ -42,7 +44,7 @@ def get_action(cls, alias: str) -> Optional[str]:
4244
return None
4345

4446
@classmethod
45-
def get_aliases(cls, action: str) -> List[str]:
47+
def get_aliases(cls, action: str) -> list[str]:
4648
"""Find all aliases for the given action. If there is no such action,
4749
None is returned.
4850

khard/address_book.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""A simple class to load and manage the vcard files from disk."""
22

3+
from __future__ import annotations
4+
35
import abc
46
import binascii
57
from collections.abc import Mapping, Sequence
68
import glob
79
import logging
810
import os
9-
from typing import Dict, Generator, Iterator, List, Optional, Union, overload
11+
from typing import Generator, Iterator, overload
1012

1113
import vobject.base
1214

@@ -42,9 +44,8 @@ class AddressBook(metaclass=abc.ABCMeta):
4244
def __init__(self, name: str) -> None:
4345
""":param name: the name to identify the address book"""
4446
self._loaded = False
45-
self.contacts: Dict[str, "carddav_object.CarddavObject"] = {}
46-
self._short_uids: Optional[Dict[str,
47-
"carddav_object.CarddavObject"]] = None
47+
self.contacts: dict[str, "carddav_object.CarddavObject"] = {}
48+
self._short_uids: None | dict[str, "carddav_object.CarddavObject"] = None
4849
self.name = name
4950

5051
def __str__(self) -> str:
@@ -83,7 +84,7 @@ def search(self, query: Query) -> Generator["carddav_object.CarddavObject",
8384
if query.match(contact):
8485
yield contact
8586

86-
def get_short_uid_dict(self, query: Query = AnyQuery()) -> Dict[
87+
def get_short_uid_dict(self, query: Query = AnyQuery()) -> dict[
8788
str, "carddav_object.CarddavObject"]:
8889
"""Create a dictionary of shortened UIDs for all contacts.
8990
@@ -154,7 +155,7 @@ class VdirAddressBook(AddressBook):
154155
"""
155156

156157
def __init__(self, name: str, path: str,
157-
private_objects: Optional[List[str]] = None,
158+
private_objects: None | list[str] = None,
158159
localize_dates: bool = True, skip: bool = False) -> None:
159160
"""
160161
:param name: the name to identify the address book
@@ -236,7 +237,7 @@ class AddressBookCollection(AddressBook, Mapping, Sequence):
236237
this class to use all other methods from the parent AddressBook class.
237238
"""
238239

239-
def __init__(self, name: str, abooks: List[VdirAddressBook]) -> None:
240+
def __init__(self, name: str, abooks: list[VdirAddressBook]) -> None:
240241
"""
241242
:param name: the name to identify the address book
242243
:param abooks: a list of address books to combine in this collection
@@ -270,11 +271,11 @@ def load(self, query: Query = AnyQuery()) -> None:
270271
len(self.contacts), self.name)
271272

272273
@overload
273-
def __getitem__(self, key: Union[int, str]) -> VdirAddressBook: ...
274+
def __getitem__(self, key: int | str) -> VdirAddressBook: ...
274275
@overload
275-
def __getitem__(self, key: slice) -> List[VdirAddressBook]: ...
276-
def __getitem__(self, key: Union[int, str, slice]
277-
) -> Union[VdirAddressBook, List[VdirAddressBook]]:
276+
def __getitem__(self, key: slice) -> list[VdirAddressBook]: ...
277+
def __getitem__(self, key: int | str | slice
278+
) -> VdirAddressBook | list[VdirAddressBook]:
278279
"""Get one or more of the backing address books by name or index
279280
280281
:param key: the name of the address book to get or its index

0 commit comments

Comments
 (0)