Grub4K commented on code in PR #37347: URL: https://github.com/apache/airflow/pull/37347#discussion_r1585279677
########## 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" Review Comment: I don't agree with this reasoning: The encoding is ambiguous, since data is written to the underlying logger. To fulfill the contract we have to return a string, but passing a valid encoding is masking the truth. `utf-8` is only fine because it can encode any value. ########## 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: `TextIOBase` and `IO[str]` (`TextIO`) are not the same. If we remove `IO[str]` we change the contract for what is returned by `sys.stdout`. Se also the comment on top of the class. -- 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]
