Skip to content

Commit e72da20

Browse files
committed
More db type hints
1 parent b5bc05d commit e72da20

File tree

12 files changed

+423
-295
lines changed

12 files changed

+423
-295
lines changed

gramps/gen/db/base.py

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#
3232
# -------------------------------------------------------------------------
3333
from __future__ import annotations
34-
from typing import NoReturn
34+
from typing import Dict, Generator, List
3535
import logging
3636

3737
# -------------------------------------------------------------------------
@@ -117,25 +117,25 @@ def get_feature(self, feature):
117117
"""
118118
return self.__feature.get(feature, None) # can also be explicitly None
119119

120-
def set_feature(self, feature, value):
120+
def set_feature(self, feature, value) -> None:
121121
"""
122122
Databases can implement certain features.
123123
"""
124124
self.__feature[feature] = value
125125

126-
def close(self):
126+
def close(self) -> None:
127127
"""
128128
Close the specified database.
129129
"""
130130
raise NotImplementedError
131131

132-
def db_has_bm_changes(self):
132+
def db_has_bm_changes(self) -> bool:
133133
"""
134134
Return whether there were bookmark changes during the session.
135135
"""
136136
raise NotImplementedError
137137

138-
def find_backlink_handles(self, handle, include_classes=None):
138+
def find_backlink_handles(self, handle: AnyHandle, include_classes=None):
139139
"""
140140
Find all objects that hold a reference to the object handle.
141141
@@ -645,7 +645,9 @@ def get_tag_from_handle(self, handle: TagHandle) -> Tag | None:
645645
"""
646646
raise NotImplementedError
647647

648-
def get_citation_handles(self, sort_handles=False, locale=glocale):
648+
def get_citation_handles(
649+
self, sort_handles: bool = False, locale=glocale
650+
) -> List[CitationHandle]:
649651
"""
650652
Return a list of database handles, one handle for each Citation in
651653
the database.
@@ -657,7 +659,7 @@ def get_citation_handles(self, sort_handles=False, locale=glocale):
657659
"""
658660
raise NotImplementedError
659661

660-
def get_event_handles(self):
662+
def get_event_handles(self) -> List[EventHandle]:
661663
"""
662664
Return a list of database handles, one handle for each Event in the
663665
database.
@@ -667,7 +669,9 @@ def get_event_handles(self):
667669
"""
668670
raise NotImplementedError
669671

670-
def get_family_handles(self, sort_handles=False, locale=glocale):
672+
def get_family_handles(
673+
self, sort_handles: bool = False, locale=glocale
674+
) -> List[FamilyHandle]:
671675
"""
672676
Return a list of database handles, one handle for each Family in
673677
the database.
@@ -682,7 +686,9 @@ def get_family_handles(self, sort_handles=False, locale=glocale):
682686
"""
683687
raise NotImplementedError
684688

685-
def get_media_handles(self, sort_handles=False, locale=glocale):
689+
def get_media_handles(
690+
self, sort_handles: bool = False, locale=glocale
691+
) -> List[MediaHandle]:
686692
"""
687693
Return a list of database handles, one handle for each Media in
688694
the database.
@@ -697,7 +703,7 @@ def get_media_handles(self, sort_handles=False, locale=glocale):
697703
"""
698704
raise NotImplementedError
699705

700-
def get_note_handles(self):
706+
def get_note_handles(self) -> List[NoteHandle]:
701707
"""
702708
Return a list of database handles, one handle for each Note in the
703709
database.
@@ -707,7 +713,9 @@ def get_note_handles(self):
707713
"""
708714
raise NotImplementedError
709715

710-
def get_person_handles(self, sort_handles=False, locale=glocale):
716+
def get_person_handles(
717+
self, sort_handles: bool = False, locale=glocale
718+
) -> List[PersonHandle]:
711719
"""
712720
Return a list of database handles, one handle for each Person in
713721
the database.
@@ -722,7 +730,9 @@ def get_person_handles(self, sort_handles=False, locale=glocale):
722730
"""
723731
raise NotImplementedError
724732

725-
def get_place_handles(self, sort_handles=False, locale=glocale):
733+
def get_place_handles(
734+
self, sort_handles: bool = False, locale=glocale
735+
) -> List[PlaceHandle]:
726736
"""
727737
Return a list of database handles, one handle for each Place in
728738
the database.
@@ -737,7 +747,7 @@ def get_place_handles(self, sort_handles=False, locale=glocale):
737747
"""
738748
raise NotImplementedError
739749

740-
def get_repository_handles(self):
750+
def get_repository_handles(self) -> List[RepositoryHandle]:
741751
"""
742752
Return a list of database handles, one handle for each Repository in
743753
the database.
@@ -747,7 +757,9 @@ def get_repository_handles(self):
747757
"""
748758
raise NotImplementedError
749759

750-
def get_source_handles(self, sort_handles=False, locale=glocale):
760+
def get_source_handles(
761+
self, sort_handles: bool = False, locale=glocale
762+
) -> List[SourceHandle]:
751763
"""
752764
Return a list of database handles, one handle for each Source in
753765
the database.
@@ -762,7 +774,9 @@ def get_source_handles(self, sort_handles=False, locale=glocale):
762774
"""
763775
raise NotImplementedError
764776

765-
def get_tag_handles(self, sort_handles=False, locale=glocale):
777+
def get_tag_handles(
778+
self, sort_handles: bool = False, locale=glocale
779+
) -> List[TagHandle]:
766780
"""
767781
Return a list of database handles, one handle for each Tag in
768782
the database.
@@ -899,7 +913,7 @@ def get_name_group_keys(self):
899913
"""
900914
raise NotImplementedError
901915

902-
def get_name_group_mapping(self, surname):
916+
def get_name_group_mapping(self, surname: str) -> str:
903917
"""
904918
Return the default grouping name for a surname.
905919
"""
@@ -971,55 +985,55 @@ def get_person_event_types(self):
971985
"""
972986
raise NotImplementedError
973987

974-
def get_raw_citation_data(self, handle: CitationHandle) -> Citation:
988+
def get_raw_citation_data(self, handle: CitationHandle) -> Citation | None:
975989
"""
976990
Return raw (serialized and pickled) Citation object from handle
977991
"""
978992
raise NotImplementedError
979993

980-
def get_raw_event_data(self, handle: EventHandle) -> Event:
994+
def get_raw_event_data(self, handle: EventHandle) -> Event | None:
981995
"""
982996
Return raw (serialized and pickled) Event object from handle
983997
"""
984998
raise NotImplementedError
985999

986-
def get_raw_family_data(self, handle: FamilyHandle) -> Family:
1000+
def get_raw_family_data(self, handle: FamilyHandle) -> Family | None:
9871001
"""
9881002
Return raw (serialized and pickled) Family object from handle
9891003
"""
9901004
raise NotImplementedError
9911005

992-
def get_raw_media_data(self, handle: MediaHandle) -> Media:
1006+
def get_raw_media_data(self, handle: MediaHandle) -> Media | None:
9931007
"""
9941008
Return raw (serialized and pickled) Family object from handle
9951009
"""
9961010
raise NotImplementedError
9971011

998-
def get_raw_note_data(self, handle: NoteHandle) -> Note:
1012+
def get_raw_note_data(self, handle: NoteHandle) -> Note | None:
9991013
"""
10001014
Return raw (serialized and pickled) Note object from handle
10011015
"""
10021016
raise NotImplementedError
10031017

1004-
def get_raw_person_data(self, handle: PersonHandle) -> Person:
1018+
def get_raw_person_data(self, handle: PersonHandle) -> Person | None:
10051019
"""
10061020
Return raw (serialized and pickled) Person object from handle
10071021
"""
10081022
raise NotImplementedError
10091023

1010-
def get_raw_place_data(self, handle: PlaceHandle) -> Place:
1024+
def get_raw_place_data(self, handle: PlaceHandle) -> Place | None:
10111025
"""
10121026
Return raw (serialized and pickled) Place object from handle
10131027
"""
10141028
raise NotImplementedError
10151029

1016-
def get_raw_repository_data(self, handle: RepositoryHandle) -> Repository:
1030+
def get_raw_repository_data(self, handle: RepositoryHandle) -> Repository | None:
10171031
"""
10181032
Return raw (serialized and pickled) Repository object from handle
10191033
"""
10201034
raise NotImplementedError
10211035

1022-
def get_raw_source_data(self, handle: SourceHandle) -> Source:
1036+
def get_raw_source_data(self, handle: SourceHandle) -> Source | None:
10231037
"""
10241038
Return raw (serialized and pickled) Source object from handle
10251039
"""
@@ -1184,121 +1198,121 @@ def is_open(self) -> bool:
11841198
"""
11851199
raise NotImplementedError
11861200

1187-
def iter_citations(self):
1201+
def iter_citations(self) -> Generator[Citation]:
11881202
"""
11891203
Return an iterator over objects for Citations in the database
11901204
"""
11911205
raise NotImplementedError
11921206

1193-
def iter_events(self):
1207+
def iter_events(self) -> Generator[Event]:
11941208
"""
11951209
Return an iterator over objects for Events in the database
11961210
"""
11971211
raise NotImplementedError
11981212

1199-
def iter_families(self):
1213+
def iter_families(self) -> Generator[Family]:
12001214
"""
12011215
Return an iterator over objects for Families in the database
12021216
"""
12031217
raise NotImplementedError
12041218

1205-
def iter_media(self):
1219+
def iter_media(self) -> Generator[Media]:
12061220
"""
12071221
Return an iterator over objects for Medias in the database
12081222
"""
12091223
raise NotImplementedError
12101224

1211-
def iter_notes(self):
1225+
def iter_notes(self) -> Generator[Note]:
12121226
"""
12131227
Return an iterator over objects for Notes in the database
12141228
"""
12151229
raise NotImplementedError
12161230

1217-
def iter_people(self):
1231+
def iter_people(self) -> Generator[Person]:
12181232
"""
12191233
Return an iterator over objects for Persons in the database
12201234
"""
12211235
raise NotImplementedError
12221236

1223-
def iter_places(self):
1237+
def iter_places(self) -> Generator[Place]:
12241238
"""
12251239
Return an iterator over objects for Places in the database
12261240
"""
12271241
raise NotImplementedError
12281242

1229-
def iter_repositories(self):
1243+
def iter_repositories(self) -> Generator[Repository]:
12301244
"""
12311245
Return an iterator over objects for Repositories in the database
12321246
"""
12331247
raise NotImplementedError
12341248

1235-
def iter_sources(self):
1249+
def iter_sources(self) -> Generator[Source]:
12361250
"""
12371251
Return an iterator over objects for Sources in the database
12381252
"""
12391253
raise NotImplementedError
12401254

1241-
def iter_tags(self):
1255+
def iter_tags(self) -> Generator[Tag]:
12421256
"""
12431257
Return an iterator over objects for Tags in the database
12441258
"""
12451259
raise NotImplementedError
12461260

1247-
def iter_citation_handles(self):
1261+
def iter_citation_handles(self) -> Generator[CitationHandle]:
12481262
"""
12491263
Return an iterator over handles for Citations in the database
12501264
"""
12511265
raise NotImplementedError
12521266

1253-
def iter_event_handles(self):
1267+
def iter_event_handles(self) -> Generator[EventHandle]:
12541268
"""
12551269
Return an iterator over handles for Events in the database
12561270
"""
12571271
raise NotImplementedError
12581272

1259-
def iter_family_handles(self):
1273+
def iter_family_handles(self) -> Generator[FamilyHandle]:
12601274
"""
12611275
Return an iterator over handles for Families in the database
12621276
"""
12631277
raise NotImplementedError
12641278

1265-
def iter_media_handles(self):
1279+
def iter_media_handles(self) -> Generator[MediaHandle]:
12661280
"""
12671281
Return an iterator over handles for Media in the database
12681282
"""
12691283
raise NotImplementedError
12701284

1271-
def iter_note_handles(self):
1285+
def iter_note_handles(self) -> Generator[NoteHandle]:
12721286
"""
12731287
Return an iterator over handles for Notes in the database
12741288
"""
12751289
raise NotImplementedError
12761290

1277-
def iter_person_handles(self):
1291+
def iter_person_handles(self) -> Generator[PersonHandle]:
12781292
"""
12791293
Return an iterator over handles for Persons in the database
12801294
"""
12811295
raise NotImplementedError
12821296

1283-
def iter_place_handles(self):
1297+
def iter_place_handles(self) -> Generator[PlaceHandle]:
12841298
"""
12851299
Return an iterator over handles for Places in the database
12861300
"""
12871301
raise NotImplementedError
12881302

1289-
def iter_repository_handles(self):
1303+
def iter_repository_handles(self) -> Generator[RepositoryHandle]:
12901304
"""
12911305
Return an iterator over handles for Repositories in the database
12921306
"""
12931307
raise NotImplementedError
12941308

1295-
def iter_source_handles(self):
1309+
def iter_source_handles(self) -> Generator[SourceHandle]:
12961310
"""
12971311
Return an iterator over handles for Sources in the database
12981312
"""
12991313
raise NotImplementedError
13001314

1301-
def iter_tag_handles(self):
1315+
def iter_tag_handles(self) -> Generator[TagHandle]:
13021316
"""
13031317
Return an iterator over handles for Tags in the database
13041318
"""
@@ -1317,7 +1331,7 @@ def load(
13171331
"""
13181332
raise NotImplementedError
13191333

1320-
def report_bm_change(self):
1334+
def report_bm_change(self) -> None:
13211335
"""
13221336
Add 1 to the number of bookmark changes during this session.
13231337
"""
@@ -1463,7 +1477,7 @@ def get_dbname(self):
14631477
"""
14641478
raise NotImplementedError
14651479

1466-
def get_summary(self):
1480+
def get_summary(self) -> Dict[str, int | str]:
14671481
"""
14681482
Returns dictionary of summary item.
14691483
Should include, if possible:

0 commit comments

Comments
 (0)