From 4987dddc0c0bd30711d8a1fe6cd9a087bb425ee1 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 30 Sep 2022 11:50:18 -0400 Subject: [PATCH] Agent: Use dict comprehension instead of for --- monkey/infection_monkey/network_scanning/tcp_scanner.py | 4 +--- .../infection_monkey/network_scanning/test_tcp_scanner.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/monkey/infection_monkey/network_scanning/tcp_scanner.py b/monkey/infection_monkey/network_scanning/tcp_scanner.py index e19b2e0eb..9b6d581e2 100644 --- a/monkey/infection_monkey/network_scanning/tcp_scanner.py +++ b/monkey/infection_monkey/network_scanning/tcp_scanner.py @@ -46,9 +46,7 @@ def _scan_tcp_ports( def _generate_tcp_scan_event( host: str, port_scan_data: Dict[int, PortScanData], event_timestamp: float ): - port_statuses = {} - for port, data in port_scan_data.items(): - port_statuses[port] = data.status + port_statuses = {port: psd.status for port, psd in port_scan_data.items()} return TCPScanEvent( source=get_agent_id(), diff --git a/monkey/tests/unit_tests/infection_monkey/network_scanning/test_tcp_scanner.py b/monkey/tests/unit_tests/infection_monkey/network_scanning/test_tcp_scanner.py index f3c897f11..2fd67590d 100644 --- a/monkey/tests/unit_tests/infection_monkey/network_scanning/test_tcp_scanner.py +++ b/monkey/tests/unit_tests/infection_monkey/network_scanning/test_tcp_scanner.py @@ -35,9 +35,7 @@ def patch_check_tcp_ports(monkeypatch, open_ports_data): def _get_tcp_scan_event(port_scan_data: PortScanData): - port_statuses = {} - for port, data in port_scan_data.items(): - port_statuses[port] = data.status + port_statuses = {port: psd.status for port, psd in port_scan_data.items()} return TCPScanEvent( source=get_agent_id(),