Skip to content

Commit

Permalink
Address arg-type, return and return-value type errors (#261)
Browse files Browse the repository at this point in the history
* Address arg-type, return and return-value type errors

Related: #258
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ssbarnea and pre-commit-ci[bot] authored Aug 15, 2024
1 parent 53bf164 commit b3e584b
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None:
if __name__ == "__main__":
"""MockQueue if running directly."""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: "MockQueue", event: dict) -> None:
Expand Down
4 changes: 2 additions & 2 deletions extensions/eda/plugins/event_source/aws_cloudtrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _get_events(events: list[dict], last_event_ids: list) -> list:
elif event_time == event["EventTime"]:
event_ids.append(event["EventId"])
result.append(event)
return result, event_time, event_ids
return [result, event_time, event_ids]


async def _get_cloudtrail_events(client: BaseClient, params: dict) -> list[dict]:
Expand Down Expand Up @@ -128,7 +128,7 @@ def connection_args(args: dict[str, Any]) -> dict[str, Any]:
if __name__ == "__main__":
"""MockQueue if running directly."""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: "MockQueue", event: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/aws_sqs_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def connection_args(args: dict[str, Any]) -> dict[str, Any]:
if __name__ == "__main__":
# MockQueue if running directly

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: "MockQueue", event: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/azure_service_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def main(
if __name__ == "__main__":
"""MockQueue if running directly."""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put_nowait(self: "MockQueue", event: dict) -> None:
Expand Down
3 changes: 2 additions & 1 deletion extensions/eda/plugins/event_source/file_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import asyncio
import concurrent.futures
from typing import Any

from watchdog.events import RegexMatchingEventHandler
from watchdog.observers import Observer
Expand Down Expand Up @@ -106,7 +107,7 @@ async def main(queue: asyncio.Queue, args: dict) -> None:
if __name__ == "__main__":
"""MockQueue if running directly."""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put_nowait(self: "MockQueue", event: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async def main( # pylint: disable=R0914

if __name__ == "__main__":

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: MockQueue, event: dict) -> None:
Expand Down
5 changes: 3 additions & 2 deletions extensions/eda/plugins/event_source/journald.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from systemd import journal # type: ignore


async def main(queue: asyncio.Queue, args: dict[str, Any]) -> str: # noqa: D417
async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None: # noqa: D417
"""Read journal entries and add them to the provided queue.
Args:
Expand Down Expand Up @@ -76,11 +76,12 @@ async def main(queue: asyncio.Queue, args: dict[str, Any]) -> str: # noqa: D417
Entry point of the program.
"""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A mock implementation of a queue that prints the event."""

async def put(self: str, event: str) -> str:
"""Add the event to the queue and print it."""
print(event) # noqa: T201
return ""

asyncio.run(main(MockQueue(), {"match": "ALL"}))
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async def receive_msg(
if __name__ == "__main__":
"""MockQueue if running directly."""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: "MockQueue", event: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/pg_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async def _handle_chunked_message(
if __name__ == "__main__":
# MockQueue if running directly

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: "MockQueue", event: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None:
if __name__ == "__main__":
# MockQueue if running directly

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: "MockQueue", event: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None:
if __name__ == "__main__":
"""MockQueue if running directly."""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: "MockQueue", event: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/url_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None:
if __name__ == "__main__":
"""MockQueue if running directly."""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: "MockQueue", event: dict) -> None:
Expand Down
5 changes: 4 additions & 1 deletion extensions/eda/plugins/event_source/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def _get_ssl_context(args: dict[str, Any]) -> ssl.SSLContext | None:
password = args.get("password", None)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
try:
if not isinstance(certfile, str): # pragma: no-cover
msg = f"certfile is not a string, got a {type(certfile)} instead."
raise ValueError(msg)
context.load_cert_chain(certfile, keyfile, password)
except Exception:
logger.exception("Failed to load certificates. Check they are valid")
Expand Down Expand Up @@ -218,7 +221,7 @@ async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None:
if __name__ == "__main__":
"""MockQueue if running directly."""

class MockQueue:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put(self: MockQueue, event: dict) -> None:
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ error_summary = true

# TODO: Remove temporary skips and close https://github.com/ansible/event-driven-ansible/issues/258
disable_error_code = [
"arg-type",
"assignment",
"attr-defined",
"index",
"misc",
"override",
"return",
"return-value",
"union-attr",
"var-annotated",
]
Expand Down

0 comments on commit b3e584b

Please sign in to comment.