From bfe1219d3410695fa214fc60a2287025e98ddb50 Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Mon, 12 Feb 2024 04:05:24 -0500 Subject: [PATCH] Fix additional encoding error (#402) --- news/402.misc.md | 1 + src/cleo/io/outputs/stream_output.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 news/402.misc.md diff --git a/news/402.misc.md b/news/402.misc.md new file mode 100644 index 00000000..f4d5d9d2 --- /dev/null +++ b/news/402.misc.md @@ -0,0 +1 @@ +Fix one additional encoding warning diff --git a/src/cleo/io/outputs/stream_output.py b/src/cleo/io/outputs/stream_output.py index 39bdd65f..200fff38 100644 --- a/src/cleo/io/outputs/stream_output.py +++ b/src/cleo/io/outputs/stream_output.py @@ -50,7 +50,12 @@ def _get_utf8_support_info(self) -> bool: """ Returns whether the stream supports the UTF-8 encoding. """ - encoding = self._stream.encoding or locale.getpreferredencoding(False) + if self._stream.encoding: + encoding = self._stream.encoding + elif sys.version_info < (3, 11): + encoding = locale.getpreferredencoding(False) + else: + encoding = locale.getencoding() try: return codecs.lookup(encoding).name == "utf-8"