Taragolis commented on code in PR #37347:
URL: https://github.com/apache/airflow/pull/37347#discussion_r1491440683


##########
airflow/utils/log/logging_mixin.py:
##########
@@ -147,18 +147,27 @@ def supports_external_link(self) -> bool:
 
 # We have to ignore typing errors here because Python I/O classes are a mess, 
and they do not
 # have the same type hierarchy defined as the `typing.IO` - they violate 
Liskov Substitution Principle
-# While it is ok to make your class derive from IOBase (and its good thing to 
do as they provide
+# While it is ok to make your class derive from TextIOBase (and its good thing 
to do as they provide
 # base implementation for IO-implementing classes, it's impossible to make 
them work with
 # IO generics (and apparently it has not even been intended)
 # See more: https://giters.com/python/typeshed/issues/6077
-class StreamLogWriter(IOBase, IO[str]):  # type: ignore[misc]
+class StreamLogWriter(TextIOBase, IO[str]):  # type: ignore[misc]
     """
     Allows to redirect stdout and stderr to logger.
 
-    :param log: The log level method to write to, ie. log.debug, log.warning
+    :param logger: The logging.Logger instance to write to
+    :param level: The log level method to write to, ie. logging.DEBUG, 
logging.WARNING
     """
 
-    encoding: None = None
+    encoding = "None"
+
+    @property
+    def mode(self):
+        return "w"
+
+    @property
+    def name(self):
+        return "<logger>"

Review Comment:
   ```suggestion
           return f"<logger: {self.logger.name}>"
   ```



##########
airflow/utils/log/logging_mixin.py:
##########
@@ -193,12 +202,15 @@ def write(self, message):
 
         :param message: message to log
         """
-        if not message.endswith("\n"):
-            self._buffer += message
-        else:
-            self._buffer += message.rstrip()
+        newline = message.endswith("\n")
+        result = message.rstrip() if newline else message
+
+        self._buffer += result
+        if newline:

Review Comment:
   Is any reason to change condition here, I guess previous one more readable.
   
   ```python
           if not message.endswith("\n"):
               self._buffer += message
           else:
               message = message.rstrip()
               self._buffer += message
               self.flush()
           return len(message)
   ```



##########
airflow/utils/log/logging_mixin.py:
##########
@@ -147,18 +147,27 @@ def supports_external_link(self) -> bool:
 
 # We have to ignore typing errors here because Python I/O classes are a mess, 
and they do not
 # have the same type hierarchy defined as the `typing.IO` - they violate 
Liskov Substitution Principle
-# While it is ok to make your class derive from IOBase (and its good thing to 
do as they provide
+# While it is ok to make your class derive from TextIOBase (and its good thing 
to do as they provide
 # base implementation for IO-implementing classes, it's impossible to make 
them work with
 # IO generics (and apparently it has not even been intended)
 # See more: https://giters.com/python/typeshed/issues/6077
-class StreamLogWriter(IOBase, IO[str]):  # type: ignore[misc]
+class StreamLogWriter(TextIOBase, IO[str]):  # type: ignore[misc]

Review Comment:
   If you would like implement some of the attribute of `TextIOBase` maybe also 
implements other?
   
   ```python
   def writable(self):
       return True
   
   def readable(self):
       return False
   
   def seekable(self):
       return False
   
   def fileno(self):
       raise OSError("Unsupported operation 'fileno'")



-- 
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]

Reply via email to