Skip to content

Commit dce53ce

Browse files
committed
Add type hints to functions according to PEP 0484
Also check PEP 3107 for further reading
1 parent aec6ef1 commit dce53ce

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

newsapi/newsapi_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
class NewsApiAuth(AuthBase):
55
# Provided by newsapi: https://newsapi.org/docs/authentication
6-
def __init__(self, api_key):
6+
def __init__(self, api_key: str):
77
self.api_key = api_key
88

99
def __call__(self, request):
1010
request.headers.update(get_auth_headers(self.api_key))
1111
return request
1212

1313

14-
def get_auth_headers(api_key):
14+
def get_auth_headers(api_key: str) -> dict:
1515
return {
1616
'Content-Type': 'Application/JSON',
1717
'Authorization': api_key

newsapi/newsapi_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
class NewsApiClient(object):
88

9-
def __init__(self, api_key):
9+
def __init__(self, api_key: str):
1010
self.auth = NewsApiAuth(api_key=api_key)
1111

12-
def get_top_headlines(self, q=None, sources=None, language='en', country=None, category=None, page_size=None,
13-
page=None):
12+
def get_top_headlines(self, q=None: str, sources=None: str, language='en': str, country=None: str, category=None: str, page_size=20: int,
13+
page=None: int) -> dict:
1414
"""
1515
Returns live top and breaking headlines for a country, specific category in a country, single source, or multiple sources..
1616
@@ -48,7 +48,7 @@ def get_top_headlines(self, q=None, sources=None, language='en', country=None, c
4848
if type(q) == str:
4949
payload['q'] = q
5050
else:
51-
raise TypeError('keyword/phrase q param should be a of type str')
51+
raise TypeError('keyword/phrase q param should be of type str')
5252

5353
# Sources
5454
if (sources is not None) and ((country is not None) or (category is not None)):
@@ -120,9 +120,9 @@ def get_top_headlines(self, q=None, sources=None, language='en', country=None, c
120120

121121
return r.json()
122122

123-
def get_everything(self, q=None, sources=None, domains=None, exclude_domains=None,
124-
from_param=None, to=None, language=None, sort_by=None, page=None,
125-
page_size=None):
123+
def get_everything(self, q=None: str, sources=None: str, domains=None: str, exclude_domains=None: str,
124+
from_param=None: str, to=None: str, language='en': str, sort_by=None: str, page=None: int,
125+
page_size=20: int) -> dict:
126126
"""
127127
Search through millions of articles from over 5,000 large and small news sources and blogs.
128128
@@ -262,7 +262,7 @@ def get_everything(self, q=None, sources=None, domains=None, exclude_domains=Non
262262

263263
return r.json()
264264

265-
def get_sources(self, category=None, language=None, country=None):
265+
def get_sources(self, category=None: str, language='en': str, country=None: str) -> dict:
266266
"""
267267
Returns the subset of news publishers that top headlines...
268268

0 commit comments

Comments
 (0)