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
re.sub returns str when processing empty unicode string #45481
Comments
While re.sub normally returns unicode strings when processing unicode, Example:
>>> print type( re.sub( "XX", "", u""))
<type 'str'>
>>> print type( re.sub( "XX", "", u"A"))
<type 'unicode'> This inconsistency could lead to annoying bugs (at least it did for me :) |
I agree. I wonder if it should return Unicode as soon as *any* of the |
I would certainly expect it to return unicode when either the "modified" |
Actually, it already implements the best possible rules, *except* for |
Here's a patch. |
Here's a better patch that also fixes a few related issues. |
Fredrik, thoughts? |
Looks good to me. I still subscribe to the idea that Feel free to check this in (or assign back to you if |
(is there a way to just add a comment in the new tracker, btw, or is |
Thanks, Fredrik. |
Applied as revision 58179 to 2.5 maintenance branch, passes tests. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: