Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit a3be3e8

Browse files
committed
annotations: add annotations and enforce in linter
1 parent 40e4bb2 commit a3be3e8

File tree

7 files changed

+34
-12
lines changed

7 files changed

+34
-12
lines changed

cicd/custom_style_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def noqa_re(error_id: str = "") -> Pattern:
2828
return re.compile(rf"#\s*noqa(:\s*{error_id})?\s*\n$")
2929

3030

31-
def eprint(*strings):
31+
def eprint(*strings: str):
3232
cprint(" ".join(strings), "red", end="", attrs=["bold"])
3333

3434

examples/listen-for-events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import asyncio
55
from linkedin_messaging import LinkedInMessaging, ChallengeException
6+
from linkedin_messaging.api_objects import RealTimeEventStreamEvent
67

78
cookie_path = Path(__file__).parent.joinpath("cookies.pickle")
89

@@ -25,7 +26,7 @@ async def main():
2526
with open(cookie_path, "wb+") as cf:
2627
cf.write(linkedin.to_pickle())
2728

28-
async def on_event(event):
29+
async def on_event(event: RealTimeEventStreamEvent):
2930
print(event)
3031

3132
linkedin.add_event_listener("event", on_event)

linkedin_messaging/api_objects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ def __init__(self, urn_str: str):
1818
self.prefix = ":".join(urn_parts[:-1])
1919
self.id_parts = urn_parts[-1].strip("()").split(",")
2020

21-
def get_id(self):
21+
def get_id(self) -> str:
2222
assert len(self.id_parts) == 1
2323
return self.id_parts[0]
2424

25-
def id_str(self):
25+
def id_str(self) -> str:
2626
return ",".join(self.id_parts)
2727

28-
def __str__(self):
28+
def __str__(self) -> str:
2929
return "{}:{}".format(
3030
self.prefix,
3131
(
@@ -43,7 +43,7 @@ def __eq__(self, other: Any) -> bool:
4343
return False
4444
return self.id_parts == other.id_parts
4545

46-
def __repr__(self):
46+
def __repr__(self) -> str:
4747
return f"URN('{str(self)}')"
4848

4949

linkedin_messaging/linkedin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class ChallengeException(Exception):
7373
class LinkedInMessaging:
7474
session: aiohttp.ClientSession
7575
two_factor_payload: Dict[str, Any]
76-
event_listeners: DefaultDict[str, List[Callable[[Any], Awaitable[None]]]]
76+
event_listeners: DefaultDict[
77+
str, List[Callable[[RealTimeEventStreamEvent], Awaitable[None]]]
78+
]
7779

7880
def __init__(self):
7981
self.session = aiohttp.ClientSession()
@@ -96,10 +98,10 @@ def to_pickle(self) -> bytes:
9698
async def close(self):
9799
await self.session.close()
98100

99-
async def _get(self, relative_url: str, **kwargs) -> aiohttp.ClientResponse:
101+
async def _get(self, relative_url: str, **kwargs: Any) -> aiohttp.ClientResponse:
100102
return await self.session.get(API_BASE_URL + relative_url, **kwargs)
101103

102-
async def _post(self, relative_url: str, **kwargs) -> aiohttp.ClientResponse:
104+
async def _post(self, relative_url: str, **kwargs: Any) -> aiohttp.ClientResponse:
103105
return await self.session.post(API_BASE_URL + relative_url, **kwargs)
104106

105107
# region Authentication
@@ -375,7 +377,7 @@ async def download_profile_picture(self, picture: Picture) -> bytes:
375377
def add_event_listener(
376378
self,
377379
payload_key: str,
378-
fn: Callable[[Any], Awaitable[None]],
380+
fn: Callable[[RealTimeEventStreamEvent], Awaitable[None]],
379381
):
380382
self.event_listeners[payload_key].append(fn)
381383

poetry.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mypy = "^0.782"
4242
pytest = "^6.2.4"
4343
termcolor = "^1.1.0"
4444
pytest-cov = "^2.12.1"
45+
flake8-annotations = "^2.6.2"
4546

4647
[tool.pytest.ini_options]
4748
addopts = """

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[flake8]
2-
extend-ignore = E203, E402, E722, W503
2+
extend-ignore = E203, E402, E722, W503, ANN101, ANN102
33
exclude = .git,__pycache__,build,dist,.venv
44
max-line-length = 88
5+
suppress-none-returning = True
6+
suppress-dummy-args = True
57
extension =
68
MC1 = flake8-pep3101
79

0 commit comments

Comments
 (0)