Skip to content

Commit 7581600

Browse files
authored
Merge pull request #25009 from ccordoba12/restore-str-encoding
PR: Restore calling `str` with encoding in several places (Utils)
2 parents 387cd6a + 1d616e3 commit 7581600

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

spyder/plugins/editor/widgets/main_widget.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from pathlib import Path
2020
import re
2121
import sys
22-
import time
2322
from typing import Dict, Optional
2423
import uuid
2524

@@ -37,7 +36,6 @@
3736
from spyder.config.base import _, get_conf_path
3837
from spyder.plugins.editor.api.panel import Panel
3938
from spyder.utils import encoding, programs, sourcecode
40-
from spyder.utils.icon_manager import ima
4139
from spyder.utils.qthelpers import create_action, qbytearray_to_str
4240
from spyder.utils.misc import getcwd_or_home
4341
from spyder.widgets.findreplace import FindReplace
@@ -61,7 +59,6 @@
6159
from spyder.plugins.run.api import (
6260
RunContext, RunConfigurationMetadata, RunConfiguration,
6361
SupportedExtensionContexts, ExtendedContext)
64-
from spyder.widgets.mixins import BaseEditMixin
6562
from spyder.widgets.printer import SpyderPrinter, SpyderPrintPreviewDialog
6663
from spyder.widgets.simplecodeeditor import SimpleCodeEditor
6764

spyder/utils/encoding.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,26 @@ def decode(text, default_codec=None):
169169
try:
170170
if text.startswith(BOM_UTF8):
171171
# UTF-8 with BOM
172-
return str(text[len(BOM_UTF8):]), 'utf-8-bom'
172+
return str(text[len(BOM_UTF8) :], "utf-8"), "utf-8-bom"
173173
elif text.startswith(BOM_UTF16):
174174
# UTF-16 with BOM
175-
return str(text[len(BOM_UTF16):]), 'utf-16'
175+
return str(text[len(BOM_UTF16) :], "utf-16"), "utf-16"
176176
elif text.startswith(BOM_UTF32):
177177
# UTF-32 with BOM
178-
return str(text[len(BOM_UTF32):]), 'utf-32'
178+
return str(text[len(BOM_UTF32) :], "utf-32"), "utf-32"
179+
179180
coding = get_coding(text, default_codec=default_codec)
180181
if coding:
181182
return str(text, coding), coding
182183
except (UnicodeError, LookupError):
183184
pass
185+
184186
# Assume UTF-8
185187
try:
186-
return str(text), 'utf-8-guessed'
188+
return str(text, "utf-8"), "utf-8-guessed"
187189
except (UnicodeError, LookupError):
188190
pass
191+
189192
# Assume Latin-1 (behaviour before 3.7.1)
190193
return str(text, "latin-1"), 'latin-1-guessed'
191194

0 commit comments

Comments
 (0)