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
Codec name normalization breaks custom codecs #88886
First of all, the changes made therein are not documented correctly.
In the implementation
| Normalization works as follows: all non-alphanumeric
| characters except the dot used for Python package names are
| collapsed and replaced with a single underscore, e.g. ' -;#'
| becomes '_'. Leading and trailing underscores are removed.”
Cf. encodings/init.py
The documentation however only states that:
| Search functions are expected to take one argument, being the encoding name in all lower case letters with hyphens and spaces converted to underscores
Cf. https://docs.python.org/3/library/codecs.html#codecs.register
Secondly, this change breaks lots of iconv codecs with the python-iconv binding. E.g. ASCII//TRANSLIT is now normalized to ascii_translit, which iconv does not understand. Codec names which use hyphens also break and iinm not all of them have aliases in iconv without hyphens.
Cf. python-iconv #4
How about first looking up the given name and only then, if the given name could not be found, looking for the codec by its normalized name?
I am not sure that any normalization is needed in codecs.lookup() (except maybe normalizing the letter case). It must be done in the search function. For example, standard encodings.search_function() needs to convert encoding name to module name -- therefore filter out /, \, :, and other characters that can be special in filesystem.
Activity
bodograumann commentedon Jul 23, 2021
This is a follow up on https://bugs.python.org/issue37751 concerning normalization of codec names.
First of all, the changes made therein are not documented correctly.
In the implementation
| Normalization works as follows: all non-alphanumeric
| characters except the dot used for Python package names are
| collapsed and replaced with a single underscore, e.g. ' -;#'
| becomes '_'. Leading and trailing underscores are removed.”
Cf. encodings/init.py
The documentation however only states that:
| Search functions are expected to take one argument, being the encoding name in all lower case letters with hyphens and spaces converted to underscores
Cf. https://docs.python.org/3/library/codecs.html#codecs.register
Secondly, this change breaks lots of iconv codecs with the python-iconv binding. E.g.
ASCII//TRANSLITis now normalized toascii_translit, which iconv does not understand. Codec names which use hyphens also break and iinm not all of them have aliases in iconv without hyphens.Cf. python-iconv #4
How about first looking up the given name and only then, if the given name could not be found, looking for the codec by its normalized name?
serhiy-storchaka commentedon Jul 21, 2025
I am not sure that any normalization is needed in
codecs.lookup()(except maybe normalizing the letter case). It must be done in the search function. For example, standardencodings.search_function()needs to convert encoding name to module name -- therefore filter out/,\,:, and other characters that can be special in filesystem.serhiy-storchaka commentedon Jul 21, 2025
@vstinner, I think that #81932 should be rolled back. Even more, there is no reason to convert space to minus.
pythongh-88886: Remove excessive encoding name normalization
pythongh-88886: Remove excessive encoding name normalization
pythongh-88886: Remove excessive encoding name normalization
gh-88886: Remove excessive encoding name normalization (GH-137167)
pythongh-88886: Remove excessive encoding name normalization (pythonG…