Skip to content

Commit ce688a2

Browse files
committed
include return types in one-line docstring for @Property
1 parent 46436d9 commit ce688a2

File tree

3 files changed

+30
-123
lines changed

3 files changed

+30
-123
lines changed

libzim/libzim.pyx

Lines changed: 27 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,7 @@ cdef class _Creator:
496496
497497
@property
498498
def filename(self) -> pathlib.Path:
499-
"""Path of the ZIM Archive.
500-
501-
Returns:
502-
(pathlib.Path): Archive\'s ZIM file path.
503-
"""
499+
"""pathlib.Path: Path of the ZIM Archive."""
504500
return self._filename
505501
506502
class ContentProvider:
@@ -841,34 +837,22 @@ cdef class Entry:
841837
842838
@property
843839
def title(self) -> str:
844-
"""The title of the entry.
845-
846-
Returns:
847-
(str): The UTF-8 decoded title of the entry.
848-
"""
840+
"""The UTF-8 decoded title of the entry."""
849841
return self.c_entry.getTitle().decode('UTF-8')
850842
851843
@property
852844
def path(self) -> str:
853-
"""The path of the entry.
854-
855-
Returns:
856-
(str): The UTF-8 decoded path of the entry.
857-
"""
845+
"""str: The UTF-8 decoded path of the entry."""
858846
return self.c_entry.getPath().decode("UTF-8", "strict")
859847
860848
@property
861849
def _index(self) -> pyint:
862-
"""Internal index in Archive"""
850+
"""int: Internal index in Archive"""
863851
return self.c_entry.getIndex()
864852
865853
@property
866854
def is_redirect(self) -> pybool:
867-
"""Whether entry is a redirect.
868-
869-
Returns:
870-
(bool): True if the Entry is a redirect, otherwise False.
871-
"""
855+
"""bool: Whether entry is a redirect."""
872856
return self.c_entry.isRedirect()
873857
874858
def get_redirect_entry(self) -> Entry:
@@ -920,55 +904,36 @@ cdef class Item:
920904
921905
@property
922906
def title(self) -> str:
923-
"""The title of the Item.
924-
925-
Returns:
926-
(str): The UTF-8 decoded title of the item.
927-
"""
907+
"""str: The UTF-8 decoded title of the item."""
928908
return self.c_item.getTitle().decode('UTF-8')
929909
930910
@property
931911
def path(self) -> str:
932-
"""The path of the Item.
933-
934-
Returns:
935-
(str): The UTF-8 decoded path of the item.
912+
"""str: The UTF-8 decoded path of the item.
936913
"""
937914
return self.c_item.getPath().decode("UTF-8", "strict")
938915
939916
@property
940917
def content(self) -> memoryview:
941-
"""The data associated to the item.
942-
943-
Returns:
944-
(memoryview): A memory view of the item's data.
945-
"""
918+
"""memoryview: The data associated to the item."""
946919
if not self._haveBlob:
947920
self._blob = ReadingBlob.from_blob(move(self.c_item.getData(<int> 0)))
948921
self._haveBlob = True
949922
return memoryview(self._blob)
950923
951924
@property
952925
def mimetype(self) -> str:
953-
"""The mimetype of the item.
954-
955-
Returns:
956-
(str): The mimetype of the item.
957-
"""
926+
"""str: The mimetype of the item."""
958927
return self.c_item.getMimetype().decode('UTF-8')
959928
960929
@property
961930
def _index(self) -> pyint:
962-
"""Internal index in Archive"""
931+
"""int: Internal index in Archive"""
963932
return self.c_item.getIndex()
964933
965934
@property
966935
def size(self) -> pyint:
967-
"""The size of the item.
968-
969-
Returns:
970-
(int): The size (in bytes) of the item.
971-
"""
936+
"""int: The size (in bytes) of the item."""
972937
return self.c_item.getSize()
973938
974939
def __repr__(self) -> str:
@@ -1006,20 +971,12 @@ cdef class Archive:
1006971
1007972
@property
1008973
def filename(self) -> pathlib.Path:
1009-
"""Path (not just file name) of the ZIM Archive.
1010-
1011-
Returns:
1012-
(pathlib.Path): Archive\'s ZIM file path.
1013-
"""
974+
"""pathlib.Path: Archive's ZIM file path."""
1014975
return self._filename
1015976

1016977
@property
1017978
def filesize(self) -> pyint:
1018-
"""Total size of ZIM file (or sum of files if split).
1019-
1020-
Returns:
1021-
(int): The total size of ZIM file (or sum of files if split).
1022-
"""
979+
"""int: Total size of ZIM file (or sum of files if split)."""
1023980
return self.c_archive.getFilesize()
1024981

1025982
def has_entry_by_path(self, path: str) -> pybool:
@@ -1091,11 +1048,7 @@ cdef class Archive:
10911048

10921049
@property
10931050
def metadata_keys(self) -> List[str]:
1094-
"""List of Metadata keys present in this archive.
1095-
1096-
Returns:
1097-
(list[str]): The list of metada in this archive.
1098-
"""
1051+
"""list[str]: List of Metadata keys present in this archive."""
10991052
return [key.decode("UTF-8", "strict") for key in self.c_archive.getMetadataKeys()]
11001053

11011054
def get_metadata_item(self, name: str) -> Item:
@@ -1135,86 +1088,51 @@ cdef class Archive:
11351088
11361089
@property
11371090
def has_main_entry(self) -> pybool:
1138-
"""Whether Archive has a main entry set.
1139-
1140-
Returns:
1141-
(bool): True if the archive has a main entry, otherwise False.
1142-
"""
1091+
"""bool: Whether Archive has a main entry set."""
11431092
return self.c_archive.hasMainEntry()
11441093
11451094
@property
11461095
def main_entry(self) -> Entry:
1147-
"""Get the main entry of the Archive.
1148-
1149-
Returns:
1150-
(Entry): The main entry.
1151-
"""
1096+
"""Entry: The main entry of the Archive."""
11521097
return Entry.from_entry(move(self.c_archive.getMainEntry()))
11531098
11541099
@property
11551100
def uuid(self) -> UUID:
1156-
"""The uuid of the archive.
1157-
1158-
Returns:
1159-
(uuid.UUID): The uuid of hte archive.
1160-
"""
1101+
"""uuid.UUID: The uuid of the archive."""
11611102
return UUID(self.c_archive.getUuid().hex())
11621103
11631104
@property
11641105
def has_new_namespace_scheme(self) -> pybool:
1165-
"""Whether Archive is using new “namespaceless” namespace scheme
1166-
1167-
Returns:
1168-
(bool): True if the archive uses the new namespace scheme, otherwise False.
1169-
"""
1106+
"""bool: Whether Archive is using new “namespaceless” namespace scheme."""
11701107
return self.c_archive.hasNewNamespaceScheme()
11711108
11721109
@property
11731110
def is_multipart(self) -> pybool:
1174-
"""Whether Archive is multipart (split over multiple files).
1175-
1176-
Returns:
1177-
(bool): True if the archive is split in different files, otherwise False.
1178-
"""
1111+
"""bool: Whether Archive is multipart (split over multiple files)."""
11791112
return self.c_archive.isMultiPart()
11801113
11811114
@property
11821115
def has_fulltext_index(self) -> pybool:
1183-
"""Whether Archive includes a full-text index.
1184-
1185-
Returns:
1186-
(bool): True if the archive has a title index.
1187-
"""
1116+
"""bool: Whether Archive includes a full-text index."""
11881117
return self.c_archive.hasFulltextIndex()
11891118
11901119
@property
11911120
def has_title_index(self) -> pybool:
1192-
"""Whether Archive includes a title index.
1193-
1194-
Returns:
1195-
(bool): True if the archive has a title index, otherwise False.
1196-
"""
1121+
"""bool: Whether Archive includes a title index."""
11971122
return self.c_archive.hasTitleIndex()
11981123
11991124
@property
12001125
def has_checksum(self) -> str:
1201-
"""Whether Archive includes a checksum of its content.
1126+
"""bool: Whether Archive includes a checksum of its content.
12021127

12031128
The checksum is not the checksum of the file. It is an internal
12041129
checksum stored in the zim file.
1205-
1206-
Returns:
1207-
(bool): True if the archive has a checksum, otherwise False.
12081130
"""
12091131
return self.c_archive.hasChecksum()
12101132
12111133
@property
12121134
def checksum(self) -> str:
1213-
"""Archive's checksum.
1214-
1215-
Returns:
1216-
(str): The checksum stored in the archive.
1217-
"""
1135+
"""str: The checksum stored in the archive."""
12181136
return self.c_archive.getChecksum().decode("UTF-8", "strict")
12191137
12201138
def check(self) -> pybool:
@@ -1227,31 +1145,25 @@ cdef class Archive:
12271145
12281146
@property
12291147
def entry_count(self) -> pyint:
1230-
"""Number of user entries in Archive.
1148+
"""int: Number of user entries in Archive.
12311149

12321150
If Archive doesn't support “user entries”
12331151
then this returns `all_entry_count`.
1234-
1235-
Returns:
1236-
(int): The number of user entries in the archive.
12371152
"""
12381153
return self.c_archive.getEntryCount()
12391154
12401155
@property
12411156
def all_entry_count(self) -> pyint:
1242-
"""Number of entries in Archive.
1157+
"""int: Number of entries in Archive.
12431158

12441159
Total number of entries in the archive, including internal entries
12451160
created by libzim itself, metadata, indexes, etc.
1246-
1247-
Returns:
1248-
(int): The number of all entries in the archive.
12491161
"""
12501162
return self.c_archive.getAllEntryCount()
12511163
12521164
@property
12531165
def article_count(self) -> pyint:
1254-
"""Number of “articles” in the Archive.
1166+
"""int: Number of “articles” in the Archive.
12551167

12561168
If Archive has_new_namespace_scheme then this is the
12571169
number of Entry with “FRONT_ARTICLE” Hint.
@@ -1261,20 +1173,12 @@ cdef class Archive:
12611173
Note: a few ZIM created during transition might have new scheme but no
12621174
listing, resulting in this returning all entries.
12631175

1264-
Returns:
1265-
(int): The number of articles in the archive.
12661176
"""
12671177
return self.c_archive.getArticleCount()
12681178
12691179
@property
12701180
def media_count(self) -> pyint:
1271-
"""Number of media in the Archive.
1272-
1273-
This definition of "media" is based on the mimetype.
1274-
1275-
Returns:
1276-
(int): The number of median in the archive.
1277-
"""
1181+
"""int: Number of media in the Archive."""
12781182
return self.c_archive.getMediaCount()
12791183
12801184
def get_illustration_sizes(self) -> Set[pyint]:

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,5 @@ plugins:
125125
# docstring style and options
126126
docstring_style: google
127127
docstring_section_style: list
128+
docstring_options:
129+
returns_type_in_property_summary: true

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ docs = [
8181
"mkdocs-gen-files==0.5.0",
8282
"mkdocs-literate-nav==0.6.1",
8383
"mkdocs-include-markdown-plugin==7.1.2",
84+
"griffe==1.5.6",
8485
]
8586
dev = [
8687
"pre-commit==4.0.1",

0 commit comments

Comments
 (0)