uranusjr commented on code in PR #34320:
URL: https://github.com/apache/airflow/pull/34320#discussion_r1325472667
##########
airflow/providers/cncf/kubernetes/utils/pod_manager.py:
##########
@@ -728,23 +728,23 @@ def extract_xcom_kill(self, pod: V1Pod):
self._exec_pod_command(resp, "kill -s SIGINT 1")
def _exec_pod_command(self, resp, command: str) -> str | None:
- res = None
+ res = ""
if resp.is_open():
- self.log.info("Running command... %s\n", command)
+ self.log.info("Running command... %s", command)
resp.write_stdin(command + "\n")
while resp.is_open():
resp.update(timeout=1)
while resp.peek_stdout():
- res = res + resp.read_stdout() if res else
resp.read_stdout()
- error_res = None
+ res += resp.read_stdout()
+ error_res = ""
while resp.peek_stderr():
- error_res = error_res + resp.read_stderr() if error_res
else resp.read_stderr()
+ error_res += resp.read_stderr()
if error_res:
self.log.info("stderr from command: %s", error_res)
break
if res:
return res
- return res
+ return None
Review Comment:
This function can benefit from a rewrite using early return to remove a
level indentation.
##########
airflow/providers/cncf/kubernetes/utils/pod_manager.py:
##########
@@ -728,23 +728,23 @@ def extract_xcom_kill(self, pod: V1Pod):
self._exec_pod_command(resp, "kill -s SIGINT 1")
def _exec_pod_command(self, resp, command: str) -> str | None:
- res = None
+ res = ""
if resp.is_open():
- self.log.info("Running command... %s\n", command)
+ self.log.info("Running command... %s", command)
resp.write_stdin(command + "\n")
while resp.is_open():
resp.update(timeout=1)
while resp.peek_stdout():
- res = res + resp.read_stdout() if res else
resp.read_stdout()
- error_res = None
+ res += resp.read_stdout()
+ error_res = ""
while resp.peek_stderr():
- error_res = error_res + resp.read_stderr() if error_res
else resp.read_stderr()
+ error_res += resp.read_stderr()
if error_res:
self.log.info("stderr from command: %s", error_res)
break
if res:
return res
- return res
+ return None
Review Comment:
This function can benefit from a rewrite using early return to remove a
level of indentation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]