You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
str.capitalize should titlecase the first character not uppercase #80730
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:
assignee=Noneclosed_at=<Date2019-04-12.15:36:11.742>created_at=<Date2019-04-07.10:40:51.722>labels= ['interpreter-core', 'easy', 'type-feature', '3.8', 'expert-unicode']
title='str.capitalize should titlecase the first character not uppercase'updated_at=<Date2019-04-12.18:43:26.649>user='https://github.com/stevendaprano'
I'm an absolute beginner here and this whole thing is a little overwhelming, so please bear with me. I think this would be a suitable first task for me to take on because it appears to be a simple one-line change (correct me if I'm mistaken, though).
Find the implementation of str.capitalize in unicodeobject.c and make it using the title case. See on the implementation of str.title for example.
Find tests for str.capitalize and aďd new cases. Finding the proper place for test may be the hardest part.
Update the documentation for str.capitalize. Add the versionchanged directive.
Fix the documentation for str.title. Use str.capitalize in the example.
Add the news and What's New entries.
kingdom5500 commented on Apr 10, 2019
kingdom5500mannequin
Mannequin
More actions
Thanks for clarifying all of that! I now have the patch and tests working locally. However, I'm not too sure what documentation needs to be changed for str.title. Should it specify that only the first letter of digraphs are capitalised, rather than the full character?
I sure hope I get the hang of this soon :-D
New changeset b015fc8 by Steve Dower (Kingsley M) in branch 'master': bpo-36549: str.capitalize now titlecases the first character instead of uppercasing it (GH-12804) b015fc8
Oh, apart from the What's New section. But this looks enough like a bugfix (previous behaviour "wasn't capitalizing my name correctly" - new behaviour "now capitalizes my name correctly") that it's hardly critical to advertise it on that page.
Activity
stevendaprano commentedon Apr 7, 2019
str.capitalize appears to uppercase the first character of the string, which is okay for ASCII but not for non-English letters.
For example, the letter NJ in Croatian appears as Nj at the start of words when the first character is capitalized:
Njemačka ('Germany'), not NJemačka.
(In ASCII, that's Njemacka not NJemacka.)
https://en.wikipedia.org/wiki/Gaj's_Latin_alphabet#Digraphs
But using any of:
U+01CA LATIN CAPITAL LETTER NJ
U+01CB LATIN CAPITAL LETTER N WITH SMALL LETTER J
U+01CC LATIN SMALL LETTER NJ
we get the wrong result with capitalize:
py> 'NJemačka'.capitalize()
'NJemačka'
py> 'Njemačka'.capitalize()
'NJemačka'
py> 'njemačka'.capitalize()
'NJemačka'
I believe that the correct behaviour is to titlecase the first code point and lowercase the rest, which is what the Apache library here does:
https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#capitalize-java.lang.String-
serhiy-storchaka commentedon Apr 7, 2019
I think this is a reasonable change.
Also the docs for str.title() should be fixed.
kingdom5500 commentedon Apr 9, 2019
Hello there,
I'm an absolute beginner here and this whole thing is a little overwhelming, so please bear with me. I think this would be a suitable first task for me to take on because it appears to be a simple one-line change (correct me if I'm mistaken, though).
serhiy-storchaka commentedon Apr 10, 2019
This issue is easy if you know C.
Find the implementation of str.capitalize in unicodeobject.c and make it using the title case. See on the implementation of str.title for example.
Find tests for str.capitalize and aďd new cases. Finding the proper place for test may be the hardest part.
Update the documentation for str.capitalize. Add the versionchanged directive.
Fix the documentation for str.title. Use str.capitalize in the example.
Add the news and What's New entries.
kingdom5500 commentedon Apr 10, 2019
Thanks for clarifying all of that! I now have the patch and tests working locally. However, I'm not too sure what documentation needs to be changed for str.title. Should it specify that only the first letter of digraphs are capitalised, rather than the full character?
I sure hope I get the hang of this soon :-D
zooba commentedon Apr 12, 2019
New changeset b015fc8 by Steve Dower (Kingsley M) in branch 'master':
bpo-36549: str.capitalize now titlecases the first character instead of uppercasing it (GH-12804)
b015fc8
zooba commentedon Apr 12, 2019
Thanks! I'm a big fan of this change :)
ZackerySpytz commentedon Apr 12, 2019
I think that the PR may have been merged too quickly. Serhiy had made a list, and I think that the PR was missing some necessary changes.
zooba commentedon Apr 12, 2019
What is missing? It looks like everything on Serhiy's list was done.
zooba commentedon Apr 12, 2019
Oh, apart from the What's New section. But this looks enough like a bugfix (previous behaviour "wasn't capitalizing my name correctly" - new behaviour "now capitalizes my name correctly") that it's hardly critical to advertise it on that page.