Skip to content

Commit ffd3f22

Browse files
authored
chore(deps): Bump openjd-* Rust crates to 0.7.0 (#359)
* chore(deps): Bump openjd-* Rust crates to 0.7.0 openjd-expr 0.6.0 -> 0.7.0, openjd-model 0.6.1 -> 0.7.0, and openjd-sessions 0.5.6 -> 0.5.7. Three upstream changes land, reconciled against a source diff of the published crates rather than the changelog alone: * openjd-rs#374 escapes control characters, quotes and backslashes in repr_py and repr_python. Reachable here through ExprValue.__repr__, which previously emitted literals CPython cannot parse (a raw newline terminates the string, and a NUL cannot appear in source at all) or that parse as a different value -- 'a\b' is a backspace. * openjd-rs#373 changes FormatString::validate_expressions to take a target_type and return StaticResolution. This is the breaking change the minor bump carries, and the changelog did not mention the new parameter. The binding passes None, matching the resolve and resolve_string calls above, and discards the returned value: the Python method stays pass/fail and still returns None on success. * openjd-rs#369 bounds child output reading in the Windows session helper runner. Not reachable from this repo's tests; openjd-sessions forwards to it from subprocess.rs and its coverage lives upstream. TestExprValueReprEscaping pins the #374 behaviour over 28 inputs -- quotes, backslashes, the C0 controls, DEL, and the non-ASCII characters CPython escapes by category -- using CPython's own repr() as the oracle, which is the contract Expression Language 2.2.6 states. It adds an eval(repr(v)) == v round-trip and negative controls for numeric and keyword text that must pass through unaltered. Reverting the version pins fails 60 of these cases. test_repr_list_path_with_format and test_repr_list_list_path_with_format pinned the old bug: under WINDOWS the normalised '\a' was emitted unescaped, which Python parses as BEL. Both now assert the escaped spelling and round-trip, so nothing regressed -- the bump closed a silent-corruption path those tests had frozen. THIRD-PARTY-LICENSES.txt regenerated with scripts/check_third_party_licenses.sh --update; only the three crate versions changed, with no new transitive dependencies. Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com> * docs: Sync the validate_expressions docs and note the Zs control The doc comment on the binding moved to the 3-argument crate signature but its two derived copies did not, leaving three descriptions of one method disagreeing. _openjd_rs.pyi carried the old wording verbatim, including the paragraphs above it that this branch never touched, which confirms the stub is generated from the doc comment. Regenerated by hand: the local scripts/generate_stubs.sh cannot run on macOS -- its GNU `sed -i` patch step fails on BSD sed, and once applied manually the patch is inert because building stub_gen against the local Python 3.13 defines Py_3_10, so the `#[cfg(Py_3_10)]` guard admits a PyEncodingWarning that this pyo3 does not export. No workflow verifies stub freshness, so CI could not have caught the staleness either way. Also records why "a b" sits in ESCAPING_CASES. It is not a non-ASCII space flattened in editing; it is copied from the upstream py_escape tests, where it is the negative half of the Zs discrimination -- U+0020, U+00A0 and U+3000 are all Zs and CPython escapes only the latter two. The comment now says so, since the enumeration above it listed only the characters that do get escaped. Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com> --------- Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
1 parent 1084ad1 commit ffd3f22

7 files changed

Lines changed: 157 additions & 32 deletions

File tree

‎Cargo.lock‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎THIRD-PARTY-LICENSES.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,9 +2534,9 @@ limitations under the License.
25342534
** itoa; version 1.0.18 -- https://crates.io/crates/itoa
25352535
** libc; version 0.2.189 -- https://crates.io/crates/libc
25362536
** manyhow-macros; version 0.11.4 -- https://crates.io/crates/manyhow-macros
2537-
** openjd-expr; version 0.6.0 -- https://crates.io/crates/openjd-expr
2538-
** openjd-model; version 0.6.1 -- https://crates.io/crates/openjd-model
2539-
** openjd-sessions; version 0.5.6 -- https://crates.io/crates/openjd-sessions
2537+
** openjd-expr; version 0.7.0 -- https://crates.io/crates/openjd-expr
2538+
** openjd-model; version 0.7.0 -- https://crates.io/crates/openjd-model
2539+
** openjd-sessions; version 0.5.7 -- https://crates.io/crates/openjd-sessions
25402540
** pin-project-lite; version 0.2.17 -- https://crates.io/crates/pin-project-lite
25412541
** portable-atomic; version 1.15.0 -- https://crates.io/crates/portable-atomic
25422542
** proc-macro2; version 1.0.107 -- https://crates.io/crates/proc-macro2

‎rust-bindings/Cargo.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ name = "_openjd_rs"
1212
crate-type = ["cdylib", "rlib"]
1313

1414
[dependencies]
15-
openjd-expr = "0.6.0"
16-
openjd-model = "0.6.1"
17-
openjd-sessions = "0.5.6"
15+
openjd-expr = "0.7.0"
16+
openjd-model = "0.7.0"
17+
openjd-sessions = "0.5.7"
1818
tokio = { version = "1", features = ["rt-multi-thread"] }
1919
uuid = { version = "1", features = ["v4"] }
2020
serde_json = "1"

‎rust-bindings/src/expr/format_string.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,15 @@ impl PyFormatString {
106106
/// checking through the expression tree.
107107
///
108108
/// Mirrors the Rust crate's
109-
/// `FormatString::validate_expressions(symtab, lib)`. Returns
110-
/// `None` on success.
109+
/// `FormatString::validate_expressions(symtab, lib, target_type)`.
110+
/// Returns `None` on success.
111+
///
112+
/// `target_type` is passed as `None` because `resolve` and
113+
/// `resolve_string` above resolve without one; validation has to
114+
/// observe the same values resolution will produce. The crate
115+
/// returns a `StaticResolution` (resolved-length bound and, when
116+
/// fully concrete, the resolved value); this binding is pass/fail
117+
/// only and discards it.
111118
#[pyo3(signature = (symtab, *, profile=None))]
112119
fn validate_expressions(
113120
&self,
@@ -117,7 +124,8 @@ impl PyFormatString {
117124
let st = extract_symtab(symtab)?;
118125
let lib = profile_for_call(profile);
119126
self.inner
120-
.validate_expressions(&st, &lib)
127+
.validate_expressions(&st, &lib, None)
128+
.map(|_| ())
121129
.map_err(format_string_validation_err_to_py)
122130
}
123131

‎specs/python-expr-interface.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,11 @@ except FormatStringValidationError as e:
816816
The error message embeds the ``[start, end]`` byte offsets of the
817817
failing ``{{...}}`` pair so callers can produce structured
818818
diagnostics or syntax-highlight the failing segment. Mirrors the
819-
Rust crate's ``FormatString::validate_expressions(symtab, lib)``.
819+
Rust crate's
820+
``FormatString::validate_expressions(symtab, lib, target_type)``,
821+
which the binding calls with ``target_type=None`` to match ``resolve``
822+
and ``resolve_string``. The crate returns a ``StaticResolution``; the
823+
binding is pass/fail only and discards it.
820824

821825
**Equality and hashability.** `FormatString` implements `__eq__` and
822826
`__hash__` on the raw source string. Two format strings compare equal

‎src/openjd/_openjd_rs.pyi‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,15 @@ class FormatString:
915915
checking through the expression tree.
916916
917917
Mirrors the Rust crate's
918-
`FormatString::validate_expressions(symtab, lib)`. Returns
919-
`None` on success.
918+
`FormatString::validate_expressions(symtab, lib, target_type)`.
919+
Returns `None` on success.
920+
921+
`target_type` is passed as `None` because `resolve` and
922+
`resolve_string` above resolve without one; validation has to
923+
observe the same values resolution will produce. The crate
924+
returns a `StaticResolution` (resolved-length bound and, when
925+
fully concrete, the resolved value); this binding is pass/fail
926+
only and discards it.
920927
"""
921928

922929
def __str__(self) -> builtins.str: ...

‎test/openjd/expr/test_expression_value.py‎

Lines changed: 120 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,27 +337,133 @@ def test_repr_empty_list_list_path(self) -> None:
337337

338338
@pytest.mark.parametrize("pf", [PathFormat.POSIX, PathFormat.WINDOWS])
339339
def test_repr_list_path_with_format(self, pf: PathFormat) -> None:
340-
import re
341-
342340
v = ExprValue(["/a", "/b"], type="list[path]", path_format=pf)
343-
r = repr(v)
344-
assert re.match(
345-
r"ExprValue\(\['(/|\\)a', '(/|\\)b'\], type='list\[path\]', "
346-
rf"path_format=PathFormat\.{pf.name}\)",
347-
r,
341+
# Under WINDOWS the leading "/" normalises to "\", which the
342+
# literal must escape -- so the expectation comes from CPython's
343+
# repr of the normalised items rather than a regex that would
344+
# accept either spelling. openjd-rs#374; before it, the WINDOWS
345+
# case emitted '\a', which Python parses as BEL.
346+
assert repr(v) == (
347+
f"ExprValue({v.item()!r}, type='list[path]', path_format=PathFormat.{pf.name})"
348348
)
349+
assert eval(repr(v)) == v
349350

350351
@pytest.mark.parametrize("pf", [PathFormat.POSIX, PathFormat.WINDOWS])
351352
def test_repr_list_list_path_with_format(self, pf: PathFormat) -> None:
352-
import re
353-
354353
v = ExprValue([["/a"], ["/b"]], type="list[list[path]]", path_format=pf)
355-
r = repr(v)
356-
assert re.match(
357-
r"ExprValue\(\[\['(/|\\)a'\], \['(/|\\)b'\]\], type='list\[list\[path\]\]', "
358-
rf"path_format=PathFormat\.{pf.name}\)",
359-
r,
354+
assert repr(v) == (
355+
f"ExprValue({v.item()!r}, type='list[list[path]]', path_format=PathFormat.{pf.name})"
360356
)
357+
assert eval(repr(v)) == v
358+
359+
360+
class TestExprValueReprEscaping:
361+
"""``__repr__`` escapes its embedded Python literal.
362+
363+
``repr_python`` previously escaped nothing, not even the quote or the
364+
backslash, so a value carrying a quote, a backslash or a control
365+
character produced a literal CPython cannot parse (a raw newline
366+
terminates the string; a NUL cannot appear in source at all) or, worse,
367+
one that parses as a different value (``'a\\b'`` is a backspace).
368+
Fixed upstream in openjd-rs#374, reachable here via ``__repr__``.
369+
370+
Expression Language 2.2.6 defines the escaping as following Python's
371+
own ``repr``, so ``repr(str)`` is the oracle rather than a hand-written
372+
expectation.
373+
"""
374+
375+
# Quotes and backslashes (delimiter selection and doubling), the C0
376+
# controls, DEL, and the non-ASCII characters CPython escapes by
377+
# category -- U+0085, U+00A0, U+00AD, U+2028, U+2029, U+3000, U+200B,
378+
# a private-use character and an astral non-printable -- alongside
379+
# printable non-ASCII that must survive verbatim.
380+
#
381+
# "a b" is the negative half of the Zs discrimination: U+0020,
382+
# U+00A0 and U+3000 are all Zs, and CPython escapes only the latter
383+
# two. It is the case that isolates that distinction -- the quote
384+
# cases above also carry a U+0020, but they vary the delimiter at
385+
# the same time.
386+
ESCAPING_CASES = [
387+
"it's",
388+
'say "hi"',
389+
'it\'s a "x"',
390+
"'",
391+
"a\\b",
392+
"a\\",
393+
"\\'",
394+
"hello\nworld",
395+
"a\rb",
396+
"a\r\nb",
397+
"a\tb",
398+
"a\x00b",
399+
"a\x1bb",
400+
"a\x7fb",
401+
"a\x0b\x0cb",
402+
"café",
403+
"a\U0001f600b",
404+
"a\x85b",
405+
"a\xa0b",
406+
"a\xadb",
407+
"a\u2028b",
408+
"a\u2029b",
409+
"a\u3000b",
410+
"a\u200bb",
411+
"a b",
412+
"a\ue000b",
413+
"a\U00100000b",
414+
"a\U000e0100b",
415+
]
416+
417+
@pytest.mark.parametrize("s", ESCAPING_CASES)
418+
def test_repr_string_matches_cpython(self, s: str) -> None:
419+
assert repr(ExprValue(s)) == f"ExprValue({s!r})"
420+
421+
@pytest.mark.parametrize("s", ESCAPING_CASES)
422+
def test_repr_string_round_trips(self, s: str) -> None:
423+
# The point of escaping: the literal parses back to the value.
424+
assert eval(repr(ExprValue(s))) == ExprValue(s)
425+
426+
@pytest.mark.parametrize("s", ESCAPING_CASES)
427+
def test_repr_list_element_matches_cpython(self, s: str) -> None:
428+
# ``repr_python_list`` renders elements through the same writer; a
429+
# list-only regression would go unnoticed by the scalar cases.
430+
assert repr(ExprValue([s])) == f"ExprValue({[s]!r}, type='list[string]')"
431+
432+
def test_repr_list_selects_delimiter_per_element(self) -> None:
433+
# CPython picks a delimiter per element, so these two differ.
434+
assert repr(ExprValue(["it's", "a\nb"])) == (
435+
"ExprValue([\"it's\", 'a\\nb'], type='list[string]')"
436+
)
437+
438+
def test_repr_nested_list_element_escaped(self) -> None:
439+
assert repr(ExprValue([["a\nb"]])) == r"ExprValue([['a\nb']], type='list[list[string]]')"
440+
441+
def test_repr_path_escaped(self) -> None:
442+
v = ExprValue("/tmp/a\nb.txt", type="path", path_format=PathFormat.POSIX)
443+
assert repr(v) == r"ExprValue('/tmp/a\nb.txt', type='path', path_format=PathFormat.POSIX)"
444+
445+
def test_repr_list_path_escaped(self) -> None:
446+
# ``String`` and ``Path`` share one match arm; splitting them would
447+
# leave ``list[path]`` unescaped.
448+
v = ExprValue(["/a\nb"], type="list[path]", path_format=PathFormat.POSIX)
449+
assert repr(v) == r"ExprValue(['/a\nb'], type='list[path]', path_format=PathFormat.POSIX)"
450+
451+
@pytest.mark.parametrize(
452+
"value,expected",
453+
[
454+
(42, "ExprValue(42)"),
455+
(True, "ExprValue(True)"),
456+
(None, "ExprValue(None)"),
457+
(Decimal("3.500"), "ExprValue('3.500', type='float')"),
458+
],
459+
)
460+
def test_repr_non_string_text_unaltered(self, value: object, expected: str) -> None:
461+
# Negative control: numeric and keyword text needs no escaping, so
462+
# routing it through the shared writer must not change it.
463+
assert repr(ExprValue(value)) == expected
464+
465+
def test_repr_range_expr_unaltered(self) -> None:
466+
assert repr(ExprValue("1-5", type="range_expr")) == "ExprValue('1-5', type='range_expr')"
361467

362468

363469
class TestMemorySize:

0 commit comments

Comments
 (0)