Skip to content

Commit d194a68

Browse files
committed
Preserve Unicode 3.2 widths for still-unassigned characters
Match CPython's old-UCD width policy: retain modern width defaults for characters still unassigned, and use the historical table for assigned characters. Restore the bounded east Asian width tests and retire the obsolete 9.0 override through update_lib. Permit explicit exact-source retirement of unconditional skip markers in the existing updater path, preserving its exact-match and consumed-once guards. Add focused tool tests for successful and rejected retirements. Assisted-by: OpenAI Codex: model version unavailable
1 parent cccd90d commit d194a68

4 files changed

Lines changed: 63 additions & 17 deletions

File tree

‎Lib/test/test_unicodedata.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ def test_east_asian_width(self):
698698
# New in 17.0.0
699699
self.assertEqual(eaw('\U00016FF2'), 'N' if self.old else 'W')
700700

701-
@unittest.skip("TODO: RUSTPYTHON; AssertionError: 'N' != 'W' (passed on latest, fails on 3.2)")
702701
def test_east_asian_width_unassigned(self):
703702
eaw = self.db.east_asian_width
704703
# unassigned
@@ -1100,10 +1099,6 @@ def test_block_invalid_input(self):
11001099
self.assertRaises(TypeError, self.db.block, '')
11011100
self.assertRaises(TypeError, self.db.block, 'xx')
11021101

1103-
@unittest.expectedFailure # TODO: RUSTPYTHON; + N
1104-
def test_east_asian_width_9_0_changes(self):
1105-
return super().test_east_asian_width_9_0_changes()
1106-
11071102
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module 'unicodedata' has no attribute 'digit'
11081103
def test_function_checksum(self):
11091104
return super().test_function_checksum()

‎crates/unicode/src/data.rs‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,19 +380,12 @@ impl Ucd {
380380
pub fn east_asian_width(&self, c: CodePoint) -> &'static str {
381381
c.to_char()
382382
.and_then(|c| {
383-
if self.modern {
383+
if self.modern || GeneralCategory::for_char(c) == GeneralCategory::Unassigned {
384384
Some(EastAsianWidth::for_char(c))
385385
} else {
386386
cold_path();
387-
// CPython overrides characters in the PUA for 3.2.0.
388-
// Basic Multilingual Plane:
389-
// https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane
390-
// https://en.wikipedia.org/wiki/Private_Use_Areas
391-
// https://www.unicode.org/reports/tr11/tr11-10.html
392-
// https://www.unicode.org/reports/tr11/
393-
//
394-
// Currently, this implementation is incomplete because I can't figure
395-
// out what CPython is doing.
387+
// CPython keeps modern width defaults for still-unassigned characters.
388+
// Assigned characters use their 3.2 width, or Neutral if new since 3.2.
396389
lookup_table(EAST_ASIAN_WIDTH, c)
397390
}
398391
})

‎scripts/update_lib/patch_spec.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,12 @@ def _conditional_retirements(document, old_content):
596596
"Original conditional decorator does not match exactly once"
597597
)
598598
marker = PatchSpec.try_from_ast_node(matches[0], old_content.splitlines())
599-
if marker is None or marker.ut_method != UtMethod.ExpectedFailureIf:
599+
if marker is None or marker.ut_method not in (
600+
UtMethod.ExpectedFailureIf,
601+
UtMethod.Skip,
602+
):
600603
raise ValueError(
601-
"Only explicit expectedFailureIf retirements are supported"
604+
"Only explicit expectedFailureIf and skip retirements are supported"
602605
)
603606
result[key] = marker
604607
return result

‎scripts/update_lib/tests/test_migrate.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,61 @@ def test_other_guards_and_original_source_required(self):
745745
with self.assertRaises(ValueError):
746746
self.select(None, current, document)
747747

748+
def test_explicit_skip_retirement_preserves_other_markers(self):
749+
decorator = ' @unittest.skip("TODO: RUSTPYTHON; known limitation")\n'
750+
old = OVERRIDE_OLD.replace(
751+
" @unittest.expectedFailure # TODO: RUSTPYTHON; old failure\n",
752+
decorator,
753+
)
754+
755+
def authorize(document):
756+
document["retire_conditional"] = [
757+
{
758+
"class": "Example",
759+
"method": "test_known",
760+
"decorator": decorator,
761+
}
762+
]
763+
764+
with patch(__name__ + ".OVERRIDE_OLD", old):
765+
status, result = MarkerOverrideTests().invoke(authorize)
766+
self.assertEqual(status, 0)
767+
self.assertNotIn("known limitation", result)
768+
self.assertIn('unittest.skip("TODO: RUSTPYTHON; retained guard")', result)
769+
status, result = MarkerOverrideTests().invoke()
770+
self.assertEqual(status, 1)
771+
self.assertEqual(result, old)
772+
773+
def test_skip_retirement_fails_closed(self):
774+
self.decorator = ' @unittest.skip("TODO: RUSTPYTHON; known limitation")\n'
775+
for change in (
776+
"text",
777+
"duplicate",
778+
"retained",
779+
"duplicate_source",
780+
"skipIf",
781+
"skipUnless",
782+
):
783+
old, current, document = self.fixture()
784+
if change == "text":
785+
document["retire_conditional"][0]["decorator"] = self.decorator.replace(
786+
'"', "'"
787+
)
788+
elif change == "duplicate":
789+
document["retire_conditional"] *= 2
790+
elif change == "retained":
791+
document["patches"] = patches_to_json(current)
792+
elif change == "duplicate_source":
793+
old = old.replace(self.decorator, self.decorator * 2)
794+
current = extract_patches(old)
795+
else:
796+
replacement = self.decorator.replace("skip(", change + "(True, ")
797+
old = old.replace(self.decorator, replacement)
798+
current = extract_patches(old)
799+
document["retire_conditional"][0]["decorator"] = replacement
800+
with self.subTest(change=change), self.assertRaises(ValueError):
801+
self.select(old, current, document)
802+
748803
def test_cli_conditional_retirement_preserves_remaining_markers(self):
749804
old = OVERRIDE_OLD.replace(
750805
" @unittest.expectedFailure # TODO: RUSTPYTHON; old failure\n",

0 commit comments

Comments
 (0)