Skip to content

In codecs, function 'normalizestring' should convert both spaces and hyphens to underscores. #81932

Closed

Description

@qigangxu
mannequin
BPO 37751
Nosy @malemburg, @gpshead, @vstinner, @mark-summerfield, @ezio-melotti, @methane, @miss-islington, @shihai1991, @qigangxu, @akdor1154, @bodograumann
PRs
  • bpo-37751: Fix normalizestring() with hyphens and spaces converted to underscores #15092
  • bpo-37751: Document the change in What's New in Python 3.9 #17997
  • bpo-37751: Document the change in What's New in Python 3.9 #23096
  • bpo-37751: Update codecs.register() doc. #25643
  • [3.9] bpo-37751: Document codecs.lookup() change in What's New in Python 3.9 (GH-23096) #25659
  • [3.9] bpo-37751: Update codecs.register() doc. (GH-25643) #25677
  • 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 = None
    closed_at = <Date 2021-04-24.16:55:03.898>
    created_at = <Date 2019-08-03.11:34:13.329>
    labels = ['type-bug', '3.9', 'expert-unicode']
    title = "In codecs, function 'normalizestring' should convert both spaces and hyphens to underscores."
    updated_at = <Date 2022-01-25.00:29:03.446>
    user = 'https://github.com/qigangxu'

    bugs.python.org fields:

    activity = <Date 2022-01-25.00:29:03.446>
    actor = 'gregory.p.smith'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-24.16:55:03.898>
    closer = 'shihai1991'
    components = ['Unicode']
    creation = <Date 2019-08-03.11:34:13.329>
    creator = 'qigangxu'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37751
    keywords = ['patch']
    message_count = 31.0
    messages = ['348953', '348954', '348956', '348959', '349448', '350086', '350087', '350155', '359970', '359971', '359972', '359973', '359974', '360005', '391648', '391652', '391653', '391654', '391664', '391666', '391671', '391785', '392077', '392159', '392161', '392178', '395730', '395764', '411536', '411537', '411538']
    nosy_count = 11.0
    nosy_names = ['lemburg', 'gregory.p.smith', 'vstinner', 'mark', 'ezio.melotti', 'methane', 'miss-islington', 'shihai1991', 'qigangxu', 'akdor1154', 'bodograumann']
    pr_nums = ['15092', '17997', '23096', '25643', '25659', '25677']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37751'
    versions = ['Python 3.9']

    Activity

    1. qigangxu commented on Aug 3, 2019

      qigangxumannequin
      MannequinAuthor

      In codecs.c, when _PyCodec_Lookup() call normalizestring(), both spaces and hyphens should be convered to underscores. Not convert spaces to hyphens.

      see:https://github.com/python/peps/blob/master/pep-0100.txt, Codecs (Coder/Decoders) Lookup

    2. qigangxu commented on Aug 3, 2019

      qigangxumannequin
      MannequinAuthor

      and I will try to fix it.

    3. shihai1991 commented on Aug 3, 2019

      @shihai1991
      Member
    4. malemburg commented on Aug 12, 2019

      @malemburg
      Member

      Jordon is right. Conversion has to be to underscores, not hyphens. I guess this bug was introduced when the normalization function was converted to C.

    5. vstinner commented on Aug 21, 2019

      @vstinner
      Member

      New changeset 20f59fe by Victor Stinner (Jordon Xu) in branch 'master':
      bpo-37751: Fix codecs.lookup() normalization (GH-15092)
      20f59fe

    6. vstinner commented on Aug 21, 2019

      @vstinner
      Member

      Thanks for the fix Jordon Xu.

      IMHO this change is not strictly a bugfix, but more like an enhancement. I close the issue.

      If you consider that a backport to Python 3.7 and 3.8 is needed, please say so.

    7. qigangxu commented on Aug 22, 2019

      qigangxumannequin
      MannequinAuthor

      Thanks vstinner. I also don't think it's necessary to backport to the old version. Close this issue is fine.

    8. hroncok commented on Jan 14, 2020

      hroncokmannequin
      Mannequin

      The change is backwards incompatible and a backport would break things. See for example how it breaks latexcodec:

      https://bugzilla.redhat.com/show_bug.cgi?id=1789613#c2

    9. vstinner commented on Jan 14, 2020

      @vstinner
      Member

      The change is backwards incompatible and a backport would break things. See for example how it breaks latexcodec:

      I reopen the issue. I proposed PR 17997 to *document* the incompatible change in What's New in Python 3.8. IMO it's a deliberate change and it's correct.

      I rely on Marc-Andre Lemburg who implemented codecs and encodings modules. He wrote: "Jordon is right. Conversion has to be to underscores, not hyphens.".

    10. 9 remaining items

    11. changed the title [-]In codecs, function 'normalizestring' should convert both spaces and hyphens to underscores.[/-] [+]In codecs, function 'normalizestring' should convert both spaces and hyphens to underscores.[/+] on Apr 23, 2021
    12. malemburg commented on Apr 23, 2021

      @malemburg
      Member

      On 23.04.2021 07:47, Inada Naoki wrote:

      Inada Naoki <[email protected]> added the comment:

      I think it is too late. Python 3.9 has been released already. Reverting the change is also breaking change.

      PEP-100 says:
      "Search functions are expected to take one argument, the encoding name in all lower case letters and with hyphens and spaces converted to underscores"
      https://www.python.org/dev/peps/pep-0100/#codecs-coder-decoders-lookup

      But codecs.register() says:
      "Search functions are expected to take one argument, being the encoding name in all lower case letters".

      I don't know historical reason why two document are inconsistent.
      https://docs.python.org/3/library/codecs.html#codecs.register

      I guess just an oversight on my part.

      PEP-100 is certainly what I meant and implemented. I should have also
      made it clear in PEP-100 that I meant lower case ASCII letters.

    13. vstinner commented on Apr 23, 2021

      @vstinner
      Member

      New changeset 32980fb by Hai Shi in branch 'master':
      bpo-37751: Document codecs.lookup() change in What's New in Python 3.9 (GH-23096)
      32980fb

    14. shihai1991 commented on Apr 24, 2021

      @shihai1991
      Member

      Thanks Marc-Andre for your supplement of PEP-100.
      Thanks Inada, victor for your review and merge.

      After PR-23096 merged, I suggest to close this bpo.
      If there have any other questions, we can reopen it again.

    15. vstinner commented on Apr 27, 2021

      @vstinner
      Member

      New changeset 531c810 by Miss Islington (bot) in branch '3.9':
      bpo-37751: Document codecs.lookup() change in What's New in Python 3.9 (GH-23096) (GH-25659)
      531c810

    16. methane commented on Apr 28, 2021

      @methane
      Member

      New changeset 5c84bb5 by Inada Naoki in branch 'master':
      bpo-37751: Update codecs.register() doc. (GH-25643)
      5c84bb5

    17. methane commented on Apr 28, 2021

      @methane
      Member

      New changeset cf9d65c by Miss Islington (bot) in branch '3.9':
      bpo-37751: Update codecs.register() doc. (GH-25643)
      cf9d65c

    18. vstinner commented on Apr 28, 2021

      @vstinner
      Member

      Thanks Inada-san for documenting the change in codecs.register() doc!

    19. bodograumann commented on Jun 13, 2021

      bodograumannmannequin
      Mannequin

      Unfortunately this is not quite finished yet.

      First of all, the change is bigger than what is documented: “Changed in version 3.9: Hyphens and spaces are converted to underscore.“

      In reality, now
      | 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

      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

      The codecs api feels extremely well-fitting for integrating iconv in python and any alternative I can think of seems unsatisfactory.
      Please advise.

    20. vstinner commented on Jun 13, 2021

      @vstinner
      Member

      The codecs api feels extremely well-fitting for integrating iconv in python and any alternative I can think of seems unsatisfactory.

      This issue is now closed, would you mind to open a new issue?

    21. gpshead commented on Jan 25, 2022

      @gpshead
      Member

      https://bugs.python.org/issue46508 filed to track fixing the acceptance and use of garbage codec values regression that this caused.

    22. gpshead commented on Jan 25, 2022

      @gpshead
      Member

      (note: this might not be the true cause of that issue; though it sounds potentially related - I haven't investigated far enough yet)

    23. gpshead commented on Jan 25, 2022

      @gpshead
      Member

      note that Bodo's own followup issue about the breaking change for python-iconv was filed as https://bugs.python.org/issue44723

    24. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions