-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-139353: Add Objects/unicode_format.c file #139491
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
Conversation
#define MAX_UNICODE _Py_MAX_UNICODE | ||
#define ensure_unicode _PyUnicode_EnsureUnicode |
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.
Should I understand that it's to avoid a refactoring in this file? do you plan to remove those defines later? (I think we could do it but in another PR)
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.
I don't plan to remove those defines. I don't think that it's worth it.
#define MAX_UNICODE _Py_MAX_UNICODE | ||
#define ensure_unicode _PyUnicode_EnsureUnicode | ||
|
||
struct unicode_formatter_t { |
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.
Can I assume that, starting from here, it's just a huge copy-paste, possibly with some names changed due to some private functions that are now _Py*
something? I can otherwise run a diff myself but I wanted to be ask (if you say "no", I'll just run the diff locally)
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.
I made few changes:
- Replace unicode_modifiable() with _PyUnicode_IsModifiable()
- Replace unicode_fill() with _PyUnicode_Fill()
- Add empty lines to have two empty lines between functions.
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.
This is a good time to consider PEP 7'ing the code, it would be nice (I would volunteer to do it :-). IIRC the main argument was that it'll ruin the blame, but that's not an issue any more.
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.
The split to a new file should have as few changes as possible so Git can calculate cross-file moves, formatting changes can be left to their own PR.
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.
I would prefer to reduce changes to the bare minimum. If someone wants to apply coding style changes, I would suggest to make a separated PR. I prefer to stick to just "move code around".
Please take your time. Some people will only be able to participate in the discussion on weekends. There are three formatters: Do we want all three formatters in one file or in three separate files? In any case I would start with merging |
In PR gh-139354, PyUnicode_FromFormat() takes 657 lines.
I propose to have one file per formatter. IMO it's already tedious to navigate in a 1000 lines file (
I started with PyUnicode_Format() since it's easy to split it. It has few "dependencies" to other I can create another PR for |
Then what will be the names for three files? Some code can be shared between formatters, so we may add the forth file for shared code and the fifth file for the header. |
In PR #139354, there are:
For the 3rd one (
So far, I didn't find any code which is shared between these 3 functions. If later we discover shared code, |
* Move PyUnicode_Format() implementation from unicodeobject.c to unicode_format.c. * Replace unicode_modifiable() with _PyUnicode_IsModifiable() * Add empty lines to have two empty lines between functions.
f099ed2
to
e7fab18
Compare
@serhiy-storchaka: So what do you think about adding |
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.
LGTM. 👍
Merged, thanks for the review. |
Uh oh!
There was an error while loading. Please reload this page.