From 762a49111821ab6b56c5d63be6a127500c24302f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= <6774676+eumiro@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:31:46 +0200 Subject: [PATCH] Refactor: Simplify dict manipulation in metrics --- airflow/metrics/otel_logger.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/airflow/metrics/otel_logger.py b/airflow/metrics/otel_logger.py index 3168e9ae65d1..3e4701ca6077 100644 --- a/airflow/metrics/otel_logger.py +++ b/airflow/metrics/otel_logger.py @@ -309,12 +309,9 @@ def get_counter(self, name: str, attributes: Attributes = None): :param attributes: Counter attributes, used to generate a unique key to store the counter. """ key = _generate_key_name(name, attributes) - if key in self.map.keys(): - return self.map[key] - else: - new_counter = self._create_counter(name) - self.map[key] = new_counter - return new_counter + if key not in self.map: + self.map[key] = self._create_counter(name) + return self.map[key] def del_counter(self, name: str, attributes: Attributes = None) -> None: """