Skip to content

Commit a963358

Browse files
authored
remove some cast_unicode (ipython#14562)
2 parents 0a67c96 + 706acc3 commit a963358

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

IPython/core/display.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from os.path import splitext
1717
from pathlib import Path, PurePath
1818

19-
from IPython.utils.py3compat import cast_unicode
19+
from typing import Optional
20+
2021
from IPython.testing.skipdoctest import skip_doctest
2122
from . import display_functions
2223

@@ -518,7 +519,7 @@ class SVG(DisplayObject):
518519
_read_flags = 'rb'
519520
# wrap data in a property, which extracts the <svg> tag, discarding
520521
# document headers
521-
_data = None
522+
_data: Optional[str] = None
522523

523524
@property
524525
def data(self):
@@ -540,8 +541,10 @@ def data(self, svg):
540541
# fallback on the input, trust the user
541542
# but this is probably an error.
542543
pass
543-
svg = cast_unicode(svg)
544-
self._data = svg
544+
if isinstance(svg, bytes):
545+
self._data = svg.decode(errors="replace")
546+
else:
547+
self._data = svg
545548

546549
def _repr_svg_(self):
547550
return self._data_and_metadata()

IPython/lib/latextools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from traitlets.config import get_config
1919
from traitlets.config.configurable import SingletonConfigurable
2020
from traitlets import List, Bool, Unicode
21-
from IPython.utils.py3compat import cast_unicode
2221

2322

2423
class LaTeXTool(SingletonConfigurable):
@@ -58,8 +57,9 @@ def _config_default(self):
5857
).tag(config=True)
5958

6059

61-
def latex_to_png(s, encode=False, backend=None, wrap=False, color='Black',
62-
scale=1.0):
60+
def latex_to_png(
61+
s: str, encode=False, backend=None, wrap=False, color="Black", scale=1.0
62+
):
6363
"""Render a LaTeX string to PNG.
6464
6565
Parameters
@@ -80,7 +80,7 @@ def latex_to_png(s, encode=False, backend=None, wrap=False, color='Black',
8080
None is returned when the backend cannot be used.
8181
8282
"""
83-
s = cast_unicode(s)
83+
assert isinstance(s, str)
8484
allowed_backends = LaTeXTool.instance().backends
8585
if backend is None:
8686
backend = allowed_backends[0]

IPython/utils/_process_win32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def arg_split(commandline, posix=False, strict=True):
170170
# not really a cl-arg, fallback on _process_common
171171
return py_arg_split(commandline, posix=posix, strict=strict)
172172
argvn = c_int()
173-
result_pointer = CommandLineToArgvW(py3compat.cast_unicode(commandline.lstrip()), ctypes.byref(argvn))
173+
result_pointer = CommandLineToArgvW(commandline.lstrip(), ctypes.byref(argvn))
174174
result_array_type = LPCWSTR * argvn.value
175175
result = [arg for arg in result_array_type.from_address(ctypes.addressof(result_pointer.contents))]
176176
retval = LocalFree(result_pointer)

0 commit comments

Comments
 (0)