Skip to content

Commit e108e27

Browse files
Stop being lazy
1 parent 1cfc852 commit e108e27

File tree

7 files changed

+23
-21
lines changed

7 files changed

+23
-21
lines changed

Doc/library/unicodedata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ following functions:
133133
.. function:: block(chr, /)
134134

135135
Returns the `block
136-
<https://www.unicode.org/versions/17.0.0/core-spec/chapter-3/#G64189>`_
136+
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G64189>`_
137137
assigned to the character *chr*. For example::
138138

139139
>>> unicodedata.block('S')

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ unicodedata
11351135
(Contributed by Serhiy Storchaka and Guillaume Sanchez in :gh:`74902`.)
11361136

11371137
* Add :func:`~unicodedata.block` function to return the `Unicode block
1138-
<https://www.unicode.org/versions/17.0.0/core-spec/chapter-3/#G64189>`_
1138+
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G64189>`_
11391139
assigned to a character.
11401140
(Contributed by Stan Ulbrych in :gh:`66802`.)
11411141

Lib/test/test_unicodedata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ def test_block(self):
10571057
self.assertEqual(self.db.block('\U00100000'), 'Supplementary Private Use Area-B')
10581058
self.assertEqual(self.db.block('\U0010FFFF'), 'Supplementary Private Use Area-B')
10591059

1060+
def test_block_invalid_input(self):
10601061
self.assertRaises(TypeError, self.db.block)
10611062
self.assertRaises(TypeError, self.db.block, b'x')
10621063
self.assertRaises(TypeError, self.db.block, 120)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Add :func:`unicodedata.block` function to return the `Unicode block
2-
<https://www.unicode.org/versions/17.0.0/core-spec/chapter-3/#G64189>`_ of a
2+
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G64189>`_ of a
33
character.

Modules/unicodedata.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,17 +2080,18 @@ unicodedata_block_impl(PyObject *module, int chr)
20802080
/*[clinic end generated code: output=5f8b40c49eaec75a input=0834cf2642d6eaae]*/
20812081
{
20822082
Py_UCS4 c = (Py_UCS4)chr;
2083-
int l = 0, h = BLOCK_COUNT - 1;
2084-
while (l <= h) {
2085-
int m = (l + h) / 2;
2086-
if (c < _PyUnicode_Blocks[m].s) {
2087-
h = m - 1;
2083+
int lo = 0, hi = BLOCK_COUNT - 1;
2084+
while (lo <= hi) {
2085+
int mid = (lo + hi) / 2;
2086+
if (c < _PyUnicode_Blocks[mid].start) {
2087+
hi = mid - 1;
20882088
}
2089-
else if (c > _PyUnicode_Blocks[m].e) {
2090-
l = m + 1;
2089+
else if (c > _PyUnicode_Blocks[mid].end) {
2090+
lo = mid + 1;
20912091
}
20922092
else {
2093-
return PyUnicode_FromString(_PyUnicode_BlockNames[_PyUnicode_Blocks[m].name]);
2093+
size_t name = _PyUnicode_Blocks[mid].name;
2094+
return PyUnicode_FromString(_PyUnicode_BlockNames[name]);
20942095
}
20952096
}
20962097
// Otherwise, return the default value per

Modules/unicodedata_db.h

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

Tools/unicode/makeunicodedata.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,26 +397,26 @@ def makeunicodedata(unicode, trace):
397397
names = []
398398
name_to_index = {}
399399
blocks = []
400-
for s, e, name in unicode.blocks:
400+
for start, end, name in unicode.blocks:
401401
if name not in name_to_index:
402402
name_to_index[name] = len(names)
403403
names.append(name)
404-
blocks.append((s, e, name_to_index[name]))
404+
blocks.append((start, end, name_to_index[name]))
405405

406406
fprint("static const char * const _PyUnicode_BlockNames[] = {")
407407
for name in names:
408408
fprint(' "%s",' % name)
409409
fprint("};")
410410

411411
fprint("typedef struct {")
412-
fprint(" Py_UCS4 s;")
413-
fprint(" Py_UCS4 e;")
412+
fprint(" Py_UCS4 start;")
413+
fprint(" Py_UCS4 end;")
414414
fprint(" unsigned short name;")
415415
fprint("} _PyUnicode_Block;")
416416

417417
fprint("static const _PyUnicode_Block _PyUnicode_Blocks[] = {")
418-
for s, e, name in blocks:
419-
fprint(" {0x%04X, 0x%04X, %d}," % (s, e, name))
418+
for start, end, name in blocks:
419+
fprint(" {0x%04X, 0x%04X, %d}," % (start, end, name))
420420
fprint("};")
421421
fprint(f"#define BLOCK_COUNT {len(blocks)}")
422422
fprint()
@@ -1238,8 +1238,8 @@ def __init__(self, version, ideograph_check=True):
12381238
self.blocks = []
12391239
for record in UcdFile(BLOCKS, version).records():
12401240
start_end, name = record
1241-
s, e = [int(c, 16) for c in start_end.split('..')]
1242-
self.blocks.append((s, e, name))
1241+
start, end = [int(c, 16) for c in start_end.split('..')]
1242+
self.blocks.append((start, end, name))
12431243
self.blocks.sort()
12441244

12451245
def uselatin1(self):

0 commit comments

Comments
 (0)