-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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.
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
bpo-37760: Convert from length-18 lists to a dataclass, in makeunicodedata. #15265
Merged
+94
−62
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7adaad2
bpo-37760: Convert from giant tuples to a dataclass, in makeunicodedata.
gnprice ef3bbd3
Add a NEWS entry.
gnprice 87b5a9b
Write `@dataclasses.dataclass`.
gnprice 7312337
Fix type comment for `table`.
gnprice 8061dfa
s/tuple/list/ in NEWS entry
gnprice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
Misc/NEWS.d/next/Build/2019-08-24-17-39-09.bpo-37760.f3jXuH.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The :file:`Tools/unicode/makeunicodedata.py` script, which is used for | ||
converting information from the Unicode Character Database into generated | ||
code and data used by the methods of :class:`str` and by the | ||
:mod:`unicodedata` module, now handles each character's data as a | ||
``dataclass`` with named attributes, rather than a length-18 list of | ||
different fields. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the sole reason for this tuple conversion line 1025? Can you use the
replace
method of dataclasses there? The hardcoded [:15] somewhat defeats the nice benefit of naming fields you've achieved here.(Also, I wonder if the first two loops of this function can be merged but that's orthogonal.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I think I originally did this with
replace
and that was too slow. Let's see if that reproduces...Oh right, another bit is that we need a distinct
set
for thebinary_properties
attribute of each record, so the code ends up not quite as clean as you might hope anyway. In this versionfrom_row
is the place that knows that fact, and we use it in both these loops.OK, the result is it makes the whole script about 20% slower: on my (fast) desktop, it's 8.3s in this version and 10.0s with
.replace
. Here's the patch:Certainly cleaner code that way, but the 20% speed hit (~2 extra seconds) is noticeably painful when doing development on this script and consequently running it all the time to try changes.
This tuple is quite local -- it doesn't escape this loop of 20 lines or so -- so I'd prefer to accept the short stretch of lower-level fiddling in exchange for the speedup when working on the rest of the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I suppose
[:15]
is unlikely to break too in the future given the stability ofUnicodeData.txt
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed :)