From 706acc3c48d56098ccfb3b4ae99f71e1e824c2a5 2024-10-27 18:16:36 From: M Bussonnier Date: 2024-10-27 18:16:36 Subject: [PATCH] remove some cast_unicode --- diff --git a/IPython/core/display.py b/IPython/core/display.py index c3c4401..a943447 100644 --- a/IPython/core/display.py +++ b/IPython/core/display.py @@ -16,7 +16,8 @@ from copy import deepcopy from os.path import splitext from pathlib import Path, PurePath -from IPython.utils.py3compat import cast_unicode +from typing import Optional + from IPython.testing.skipdoctest import skip_doctest from . import display_functions @@ -518,7 +519,7 @@ class SVG(DisplayObject): _read_flags = 'rb' # wrap data in a property, which extracts the tag, discarding # document headers - _data = None + _data: Optional[str] = None @property def data(self): @@ -540,8 +541,10 @@ class SVG(DisplayObject): # fallback on the input, trust the user # but this is probably an error. pass - svg = cast_unicode(svg) - self._data = svg + if isinstance(svg, bytes): + self._data = svg.decode(errors="replace") + else: + self._data = svg def _repr_svg_(self): return self._data_and_metadata() diff --git a/IPython/lib/latextools.py b/IPython/lib/latextools.py index f2aa572..7bea589 100644 --- a/IPython/lib/latextools.py +++ b/IPython/lib/latextools.py @@ -18,7 +18,6 @@ from IPython.utils.process import find_cmd, FindCmdError from traitlets.config import get_config from traitlets.config.configurable import SingletonConfigurable from traitlets import List, Bool, Unicode -from IPython.utils.py3compat import cast_unicode class LaTeXTool(SingletonConfigurable): @@ -58,8 +57,9 @@ class LaTeXTool(SingletonConfigurable): ).tag(config=True) -def latex_to_png(s, encode=False, backend=None, wrap=False, color='Black', - scale=1.0): +def latex_to_png( + s: str, encode=False, backend=None, wrap=False, color="Black", scale=1.0 +): """Render a LaTeX string to PNG. Parameters @@ -80,7 +80,7 @@ def latex_to_png(s, encode=False, backend=None, wrap=False, color='Black', None is returned when the backend cannot be used. """ - s = cast_unicode(s) + assert isinstance(s, str) allowed_backends = LaTeXTool.instance().backends if backend is None: backend = allowed_backends[0] diff --git a/IPython/utils/_process_win32.py b/IPython/utils/_process_win32.py index 36fb092..7a95978 100644 --- a/IPython/utils/_process_win32.py +++ b/IPython/utils/_process_win32.py @@ -170,7 +170,7 @@ try: # not really a cl-arg, fallback on _process_common return py_arg_split(commandline, posix=posix, strict=strict) argvn = c_int() - result_pointer = CommandLineToArgvW(py3compat.cast_unicode(commandline.lstrip()), ctypes.byref(argvn)) + result_pointer = CommandLineToArgvW(commandline.lstrip(), ctypes.byref(argvn)) result_array_type = LPCWSTR * argvn.value result = [arg for arg in result_array_type.from_address(ctypes.addressof(result_pointer.contents))] retval = LocalFree(result_pointer)