1- from .repo import AbstractRepoObject , Repo
2- from .page import Page
3- from .commit import Commit
1+ from typing import Dict , Union
42
5- from typing import Dict
3+ from mkdocs_git_authors_plugin .git .commit import Commit
4+ from mkdocs_git_authors_plugin .git .page import Page
5+ from mkdocs_git_authors_plugin .git .repo import AbstractRepoObject , Repo
66
77
88class Author (AbstractRepoObject ):
99 """
1010 Abstraction of an author in the Git repository.
1111 """
1212
13- def __init__ (self , repo : Repo , name : str , email : str ):
13+ def __init__ (self , repo : Repo , name : str , email : str ) -> None :
1414 """
1515 Instantiate an Author.
1616
@@ -24,7 +24,7 @@ def __init__(self, repo: Repo, name: str, email: str):
2424 self ._email = email
2525 self ._pages : Dict [str , dict ] = dict ()
2626
27- def add_lines (self , page : Page , commit : Commit , lines : int = 1 ):
27+ def add_lines (self , page : Page , commit : Commit , lines : int = 1 ) -> None :
2828 """
2929 Add line(s) in a given page/commit to the author's data.
3030
@@ -42,7 +42,7 @@ def add_lines(self, page: Page, commit: Commit, lines: int = 1):
4242 entry ["datetime" ] = commit_dt
4343 entry ["datetime_str" ] = commit .datetime (str )
4444
45- def contribution (self , path = None , _type = float ):
45+ def contribution (self , path = None , _type = float ) -> Union [ float , str ] :
4646 """
4747 The author's relative contribution to a page or the repository.
4848
@@ -60,17 +60,17 @@ def contribution(self, path=None, _type=float):
6060 formatted string or floating point number
6161 """
6262 lines = self .lines (path )
63- total_lines = (
63+ total_lines : int = (
6464 self .page (path )["page" ].total_lines () if path else self .repo ().total_lines ()
6565 )
6666
6767 # Some pages are empty, that case contribution is 0 by default
6868 if total_lines == 0 :
69- result = 0
69+ result = 0.0
7070 else :
7171 result = lines / total_lines
7272
73- if _type == float :
73+ if _type is float :
7474 return result
7575 else :
7676 return str (round (result * 100 , 2 )) + "%"
@@ -87,10 +87,10 @@ def datetime(self, path, fmt=str):
8787 a formatted string (fmt=str)
8888 or a datetime.datetime object with tzinfo
8989 """
90- key = "datetime_str" if fmt == str else "datetime"
90+ key = "datetime_str" if fmt is str else "datetime"
9191 return self .page (path ).get (key )
9292
93- def email (self ):
93+ def email (self ) -> str :
9494 """
9595 The author's email address
9696
@@ -101,7 +101,7 @@ def email(self):
101101 """
102102 return self ._email
103103
104- def lines (self , path = None ):
104+ def lines (self , path = None ) -> int :
105105 """
106106 The author's total number of lines on a page or in the repository.
107107
@@ -117,7 +117,7 @@ def lines(self, path=None):
117117 else :
118118 return sum ([v ["lines" ] for v in self ._pages .values ()])
119119
120- def name (self ):
120+ def name (self ) -> str :
121121 """
122122 The author's full name
123123
@@ -128,7 +128,7 @@ def name(self):
128128 """
129129 return self ._name
130130
131- def page (self , path , page = None ):
131+ def page (self , path , page = None ) -> dict :
132132 """
133133 A dictionary with the author's contribution to a page.
134134
@@ -154,7 +154,7 @@ def page(self, path, page=None):
154154 if not self ._pages .get (path ):
155155 self ._pages [path ] = {
156156 "page" : page or self .repo ().page (path ),
157- "lines" : 0
157+ "lines" : 0 ,
158158 # datetime and datetime_str will be populated later
159159 }
160160 return self ._pages [path ]
0 commit comments