GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Align Unicode lookup and decomposition with CPython 3.15 by youknowdot · Pull Request #9476 · RustPython/RustPython

Align Unicode lookup and decomposition with CPython 3.15 #9476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
youknowone merged 3 commits into RustPython:main from youknowdot:python315-unicode-lookup-decomposition-20261030
Nov 6, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Align Unicode lookup and decomposition with CPython 3.15 #9476

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
cccd90d
Align Unicode lookup and decomposition with CPython 3.15
youknowdot Oct 30, 2026
d194a68
Preserve Unicode 3.2 widths for still-unassigned characters
youknowdot Oct 30, 2026
f6b8464
Keep Unicode changes independent of updater tooling
youknowdot Nov 5, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

15 changes: 0 additions & 15 deletions 15 Lib/test/test_unicodedata.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def test_no_names_in_pua(self):
char = chr(i)
self.assertRaises(ValueError, self.db.name, char)

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: KeyError not raised by lookup
def test_lookup_nonexistant(self):
# just make sure that lookup can fail
for nonexistent in [
Expand Down Expand Up @@ -360,7 +359,6 @@ def test_bidirectional_unassigned(self):
self.assertEqual(self.db.bidirectional('\U0001FFFE'), '' if self.old else 'BN')
self.assertEqual(self.db.bidirectional('\U00010D01'), '' if self.old else 'AL')

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '<compat> 03A3 != ''
def test_decomposition(self):
self.assertEqual(self.db.decomposition('\uFFFE'),'')
self.assertEqual(self.db.decomposition('\u00bc'), '<fraction> 0031 2044 0034')
Expand Down Expand Up @@ -700,7 +698,6 @@ def test_east_asian_width(self):
# New in 17.0.0
self.assertEqual(eaw('\U00016FF2'), 'N' if self.old else 'W')

@unittest.skip("TODO: RUSTPYTHON; AssertionError: 'N' != 'W' (passed on latest, fails on 3.2)")
def test_east_asian_width_unassigned(self):
eaw = self.db.east_asian_width
# unassigned
Expand Down Expand Up @@ -1102,18 +1099,6 @@ def test_block_invalid_input(self):
self.assertRaises(TypeError, self.db.block, '')
self.assertRaises(TypeError, self.db.block, 'xx')

@unittest.expectedFailure # TODO: RUSTPYTHON; + N
def test_east_asian_width_9_0_changes(self):
return super().test_east_asian_width_9_0_changes()

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 'D4CC 11B6' != '1111 1171 11B6'
def test_decomposition(self):
return super().test_decomposition()

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: KeyError not raised by lookup
def test_lookup_nonexistant(self):
return super().test_lookup_nonexistant()

@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module 'unicodedata' has no attribute 'digit'
def test_function_checksum(self):
return super().test_function_checksum()
Expand Down
30 changes: 0 additions & 30 deletions 30 crates/unicode/build.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -371,36 +371,6 @@ fn generate_decomp(decomp_lines: Vec<(u32, String)>) {
&mut values,
);
write_slice_unordered(&mut writer, "DECOMP_RANGE", "u32", &mut decomp_ranges);

// Normalization corrections is super small - only a handful chars at the time of writing.
let reader = UnicodeLineReader::from_file_name("NormalizationCorrections.txt", true);
let mut values = Vec::new();
for line in reader {
let field = line.field(
NonZeroUsize::new(1).unwrap(),
Some(&format!(
"field 2 missing from NormalizationCorrections: {}",
line.line
)),
);
let original = u32::from_str_radix(field.trim(), 16).unwrap_or_else(|e| {
panic!("field 2 of decomp corrections should be a char in hex: {field} {e}")
});
let version = line.field(
NonZeroUsize::new(3).unwrap(),
Some(&format!(
"field 4 of decomp corrections should be a UCD version: {}",
line.line
)),
);

// `version` = when the char was updated. Therefore, we use the incorrect chars past
// 3.2.0 but skip the chars fixed in 3.2.0 because they'll already be right.
if version != "3.2.0" {
values.push((line.start, original))
}
}
write_slice_pairs(&mut writer, "DECOMP_UPDATES", "(u32, u32)", &mut values);
}

fn generate_algo_names(names: Vec<(u32, Box<str>)>) {
Expand Down
55 changes: 26 additions & 29 deletions 55 crates/unicode/src/data.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,16 @@ impl Ucd {
#[must_use]
pub fn lookup(self, search_name: &str) -> Option<LookupResult> {
if let Some(ch) = unicode_names2::character(search_name)
.filter(|&ch| {
character_name(ch).is_some_and(|name| name.eq_ignore_ascii_case(search_name))
})
.or_else(|| AlgorithmicName::check_name(search_name))
{
if self.modern {
return Some(LookupResult::Character(ch));
}
cold_path();

if !self.membership(ch) {
return None;
}

// 3.2.0 doesn't have aliases but unicode_names2 supports aliases so reject them.
if lookup_alias(search_name).is_some() {
return None;
Expand Down Expand Up @@ -381,19 +380,12 @@ impl Ucd {
pub fn east_asian_width(&self, c: CodePoint) -> &'static str {
c.to_char()
.and_then(|c| {
if self.modern {
if self.modern || GeneralCategory::for_char(c) == GeneralCategory::Unassigned {
Some(EastAsianWidth::for_char(c))
} else {
cold_path();
// CPython overrides characters in the PUA for 3.2.0.
// Basic Multilingual Plane:
// https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane
// https://en.wikipedia.org/wiki/Private_Use_Areas
// https://www.unicode.org/reports/tr11/tr11-10.html
// https://www.unicode.org/reports/tr11/
//
// Currently, this implementation is incomplete because I can't figure
// out what CPython is doing.
// CPython keeps modern width defaults for still-unassigned characters.
// Assigned characters use their 3.2 width, or Neutral if new since 3.2.
lookup_table(EAST_ASIAN_WIDTH, c)
}
})
Expand Down Expand Up @@ -445,21 +437,26 @@ impl Ucd {
return String::new();
};

// Decomposition is remarkable stable according to the normalization file,
// so the updates slice is very small - only about four char pairs. Linearly searching
// it is very fast. The file lists the original, incorrect decomp and the fixed char.
// For 3.2.0, we use the original decomp for compatibility while ignoring the update.
//
// Finally, we don't have to do anything for the latest UCD as it's already updated.
if self.modern
&& let Some((_, original)) = DECOMP_UPDATES
.iter()
.find(|&&(codep, _original)| codep == ch as u32)
{
format!("{original:04X}")
} else if let Ok(i) =
DECOMP_COMPAT.binary_search_by_key(&(ch as u32), |&(codep, _, _)| codep)
{
if !self.membership(ch) {
return String::new();
}

// CPython exposes the full Hangul L/V/T decomposition, not ICU's
// non-recursive LV/T decomposition.
let code = ch as u32;
if (0xAC00..0xD7A4).contains(&code) {
let index = code - 0xAC00;
let leading = 0x1100 + index / (21 * 28);
let vowel = 0x1161 + (index % (21 * 28)) / 28;
let trailing = index % 28;
return if trailing == 0 {
format!("{leading:04X} {vowel:04X}")
} else {
format!("{leading:04X} {vowel:04X} {:04X}", 0x11A7 + trailing)
};
}

if let Ok(i) = DECOMP_COMPAT.binary_search_by_key(&(ch as u32), |&(codep, _, _)| codep) {
// Compatibility decomposition
// `icu4x` doesn't expose a non-recursive, compatibility decomposer so we
// have to do it manually for now.
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.