-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Refactor PyUnicodeError
internal C helpers
#127787
Comments
PyUnicodeError
internal C helpersPyUnicodeError
internal C helpers
PyUnicodeError
internal C helpersPyUnicodeError
internal C helpers
I think the gh-126004 issue can be used for the related refactoring. But I guess this one works as well. IMO, there can be a |
Ah I missed this one. I can add it now (the interface is nice enough). You can comment on the PR which functions you'd like to unify even more. EDIT: I've added this one and removed un-necessary functions. Now it looks much nicer! |
…face (GH-127789) - Unify `get_unicode` and `get_string` in a single function. - Allow to retrieve the underlying `object` attribute, its size, and the adjusted 'start' and 'end', all at once. Add a new `_PyUnicodeError_GetParams` internal function for this. (In `exceptions.c`, it's somewhat common to not need all the attributes, but the compiler has opportunity to inline the function and optimize unneeded work away. Outside that file, we'll usually need all or most of them at once.) - Use a common implementation for the following functions: - `PyUnicode{Decode,Encode}Error_GetEncoding` - `PyUnicode{Decode,Encode,Translate}Error_GetObject` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}Reason` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}{Start,End}`
I can now close this one and move back to fixing the codecs. |
… interface (pythonGH-127789) - Unify `get_unicode` and `get_string` in a single function. - Allow to retrieve the underlying `object` attribute, its size, and the adjusted 'start' and 'end', all at once. Add a new `_PyUnicodeError_GetParams` internal function for this. (In `exceptions.c`, it's somewhat common to not need all the attributes, but the compiler has opportunity to inline the function and optimize unneeded work away. Outside that file, we'll usually need all or most of them at once.) - Use a common implementation for the following functions: - `PyUnicode{Decode,Encode}Error_GetEncoding` - `PyUnicode{Decode,Encode,Translate}Error_GetObject` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}Reason` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}{Start,End}`
… interface (pythonGH-127789) - Unify `get_unicode` and `get_string` in a single function. - Allow to retrieve the underlying `object` attribute, its size, and the adjusted 'start' and 'end', all at once. Add a new `_PyUnicodeError_GetParams` internal function for this. (In `exceptions.c`, it's somewhat common to not need all the attributes, but the compiler has opportunity to inline the function and optimize unneeded work away. Outside that file, we'll usually need all or most of them at once.) - Use a common implementation for the following functions: - `PyUnicode{Decode,Encode}Error_GetEncoding` - `PyUnicode{Decode,Encode,Translate}Error_GetObject` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}Reason` - `PyUnicode{Decode,Encode,Translate}Error_{Get,Set}{Start,End}`
Feature or enhancement
Proposal:
Some helpers make the realization of #126004 a bit harder as we end up with many duplicated code. In order to make the related PRs and #127694 smoother, I suggest refactoring the following helpers:
get_unicode
andget_string
as a singleas_unicode_error_attribute
.object
attribute and its size in one function, sayget_unicode_error_object_and_size
. This is typically useful for unifyingPyUnicode{Encode,Decode,Translate}Error_GetObject
public functions can use a common implementationunicode_error_get_object_impl
. Since this depends on the underlyingobject
type, the implementation function would take a flag as a parameter to indicate whether it's a bytes or a string.PyUnicode{Encode,Decode}Error_GetEncoding
public functions can use a common implementationunicode_error_get_encoding_impl
. The encoding is always a string.PyUnicode{Encode,Decode,Translate}Error_{Get,Set}Reason
public functions can use a common implementationunicode_error_{get,set}_reason_impl
. The reason is always a string.PyUnicode{Encode,Decode,Translate}_{Get,Set}{Start,End}
public functions can use a common implementationunicode_error_{get,set}_{start,end}_impl
. Since this depends on the underlyingobject
type, the implementation function would take a flag as a parameter to indicate whether it's a bytes or a string.Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
#127674 (comment)
Linked PRs
PyUnicodeErrorObject
internal interface #127789_PyUnicodeError_GetParams
#128980The text was updated successfully, but these errors were encountered: