From 1b43e2d776b2f8d7400259ab229247fc4f747f22 Mon Sep 17 00:00:00 2001 From: Anton Petnitsky <168552591+Mukller@users.noreply.github.com> Date: Wed, 29 Jul 2026 17:47:52 +0300 Subject: [PATCH] fix(path): handle bytes/memoryview keys in stringify_element (#472) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stringify_element() checks `"'" in param` to detect single-quoted strings before choosing a quote style. When param is bytes (e.g. a dict key b"foo"), the str needle `"'"` raises TypeError: a bytes-like object is required. bytes and memoryview have a canonical repr() that round-trips safely (b"foo" → repr → "b'foo'") and needs no additional quoting, so we return repr(param) immediately for those types before the str-search. Reproducer: from deepdiff import DeepDiff DeepDiff({b"foo": 1}, {b"foobar": 1}) # TypeError before, works after --- deepdiff/path.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deepdiff/path.py b/deepdiff/path.py index 3854b6bf..d9443192 100644 --- a/deepdiff/path.py +++ b/deepdiff/path.py @@ -311,6 +311,8 @@ def parse_path(path, root_element=DEFAULT_FIRST_ELEMENT, include_actions=False): def stringify_element(param, quote_str=None): + if isinstance(param, (bytes, memoryview)): + return repr(param) has_quote = "'" in param has_double_quote = '"' in param if has_quote and has_double_quote and not quote_str: