Skip to content

Tools/unicode/gencodec.py error #54761

Closed
Closed

Description

@abalkin
BPO 10552
Nosy @malemburg, @loewis, @ronaldoussoren, @abalkin, @ned-deily, @ezio-melotti, @hynek, @vadmium, @iritkatriel
Files
  • issue10552.diff
  • issue10552a.diff
  • 10552-remove-apple-files.txt: Remove problematic mapping files before parsing
  • 10552-remove-apple-files-v2.txt
  • 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 = None
    created_at = <Date 2010-11-27.20:29:09.821>
    labels = ['OS-mac', 'type-bug', 'expert-unicode']
    title = 'Tools/unicode/gencodec.py error'
    updated_at = <Date 2021-11-24.21:35:33.300>
    user = 'https://github.com/abalkin'

    bugs.python.org fields:

    activity = <Date 2021-11-24.21:35:33.300>
    actor = 'vstinner'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Demos and Tools', 'macOS', 'Unicode']
    creation = <Date 2010-11-27.20:29:09.821>
    creator = 'belopolsky'
    dependencies = []
    files = ['19842', '19874', '32565', '37687']
    hgrepos = []
    issue_num = 10552
    keywords = ['patch']
    message_count = 15.0
    messages = ['122549', '122559', '122565', '122585', '122586', '122829', '122837', '122842', '122843', '122850', '122858', '122916', '202543', '233902', '406955']
    nosy_count = 9.0
    nosy_names = ['lemburg', 'loewis', 'ronaldoussoren', 'belopolsky', 'ned.deily', 'ezio.melotti', 'hynek', 'martin.panter', 'iritkatriel']
    pr_nums = []
    priority = 'low'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10552'
    versions = ['Python 3.2', 'Python 3.4']

    Activity

    1. abalkin commented on Nov 27, 2010

      @abalkin
      MemberAuthor
      $ ../../python.exe gencodec.py MAPPINGS/VENDORS/MISC/ build/
      converting APL-ISO-IR-68.TXT to build/apl_iso_ir_68.py and build/apl_iso_ir_68.mapping
      converting ATARIST.TXT to build/atarist.py and build/atarist.mapping
      converting CP1006.TXT to build/cp1006.py and build/cp1006.mapping
      converting CP424.TXT to build/cp424.py and build/cp424.mapping
      Traceback (most recent call last):
        File "gencodec.py", line 421, in <module>
          convertdir(*sys.argv[1:])
        File "gencodec.py", line 391, in convertdir
          pymap(mappathname, map, dirprefix + codefile,name,comments)
        File "gencodec.py", line 355, in pymap
          code = codegen(name,map,encodingname,comments)
        File "gencodec.py", line 268, in codegen
          precisions=(4, 2))
        File "gencodec.py", line 152, in python_mapdef_code
          mappings = sorted(map.items())
      TypeError: unorderable types: NoneType() < int()

      It does appear to have been updated for 3.x:

      $ python2.7 gencodec.py MAPPINGS/VENDORS/MISC/ build/
      Traceback (most recent call last):
        File "gencodec.py", line 35, in <module>
          UNI_UNDEFINED = chr(0xFFFE)
      ValueError: chr() arg not in range(256)
    2. abalkin commented on Nov 27, 2010

      @abalkin
      MemberAuthor

      Attached patch addresses the issue by using -1 instead of None for missing codes. Comparison of generated encoding files to those in Lib/encodings shows only whitespace changes except one which appears to be a change on the unicode.org side:

      diff -b build/koi8_u.py ../../Lib/encodings/koi8_u.py
      1c1
      < """ Python Character Mapping Codec koi8_u generated from 'MAPPINGS/VENDORS/MISC/KOI8-U.TXT' with gencodec.py.
      ---

      """ Python Character Mapping Codec koi8_u generated from 'python-mappings/KOI8-U.TXT' with gencodec.py.
      221c221
      < '\u0491' # 0xAD -> CYRILLIC SMALL LETTER GHE WITH UPTURN
      ---
      '\u0491' # 0xAD -> CYRILLIC SMALL LETTER UKRAINIAN GHE WITH UPTURN
      237c237
      < '\u0490' # 0xBD -> CYRILLIC CAPITAL LETTER GHE WITH UPTURN
      ---
      '\u0490' # 0xBD -> CYRILLIC CAPITAL LETTER UKRAINIAN GHE WITH UPTURN
      308d307
      <

    3. malemburg commented on Nov 27, 2010

      @malemburg
      Member

      Alexander Belopolsky wrote:

      Alexander Belopolsky <belopolsky@users.sourceforge.net> added the comment:

      Attached patch addresses the issue by using -1 instead of None for missing codes. Comparison of generated encoding files to those in Lib/encodings shows only whitespace changes except one which appears to be a change on the unicode.org side:

      Please use a global constant instead of the literal -1, e.g. MISSING_CODE.
      Thanks.

      diff -b build/koi8_u.py ../../Lib/encodings/koi8_u.py
      1c1
      < """ Python Character Mapping Codec koi8_u generated from 'MAPPINGS/VENDORS/MISC/KOI8-U.TXT' with gencodec.py.
      ---
      > """ Python Character Mapping Codec koi8_u generated from 'python-mappings/KOI8-U.TXT' with gencodec.py.
      221c221
      < '\u0491' # 0xAD -> CYRILLIC SMALL LETTER GHE WITH UPTURN
      ---
      > '\u0491' # 0xAD -> CYRILLIC SMALL LETTER UKRAINIAN GHE WITH UPTURN
      237c237
      < '\u0490' # 0xBD -> CYRILLIC CAPITAL LETTER GHE WITH UPTURN
      ---
      > '\u0490' # 0xBD -> CYRILLIC CAPITAL LETTER UKRAINIAN GHE WITH UPTURN
      308d307
      <

      That's just a comment and doesn't change the semantics of the codec.

    4. abalkin commented on Nov 27, 2010

      @abalkin
      MemberAuthor

      Attached patch uses MISSING_CODE as Mark suggested. There are still errors apparently because parsecodes() may return either an int or a tuple. I think only mac encodings are affected, so I would like to commit the current patch before tackling this issue.

      $ ../../python.exe  gencodec.py MAPPINGS/VENDORS/APPLE/ build/ mac_
      converting ARABIC.TXT to build/mac_arabic.py and build/mac_arabic.mapping
      converting CELTIC.TXT to build/mac_celtic.py and build/mac_celtic.mapping
      converting CENTEURO.TXT to build/mac_centeuro.py and build/mac_centeuro.mapping
      converting CHINSIMP.TXT to build/mac_chinsimp.py and build/mac_chinsimp.mapping
      Traceback (most recent call last):
        File "gencodec.py", line 424, in <module>
          convertdir(*sys.argv[1:])
        File "gencodec.py", line 394, in convertdir
          pymap(mappathname, map, dirprefix + codefile,name,comments)
        File "gencodec.py", line 358, in pymap
          code = codegen(name,map,encodingname,comments)
        File "gencodec.py", line 271, in codegen
          precisions=(4, 2))
        File "gencodec.py", line 155, in python_mapdef_code
          mappings = sorted(map.items())
      TypeError: unorderable types: tuple() < int()
    5. abalkin commented on Nov 27, 2010

      @abalkin
      MemberAuthor

      Please ignore Makefile changes in the patch.

    6. abalkin commented on Nov 29, 2010

      @abalkin
      MemberAuthor

      Martin,

      I believe you were the last to update the unicode database. (See r85371.) Did you use python2.x to generate it or you have your own private copy of these tools?

      I noticed that genwincodecs.bat refers to c:\python26\python in 2.7 branch and c:\python30\python in py3k. Could this be an indication that these tools are out of date?

      What is the plan for maintaining these tools? Should fixes be done in 2.7 and 3.x be generated by 2to3? Or should fixes go to py3k and backported to 2.7 when they don't add new features?

    7. malemburg commented on Nov 29, 2010

      @malemburg
      Member

      gencodec.py is only rarely used, namely when adding new codecs based
      on Unicode mapping files.

      It is not run regularly on the files from ftp.unicode.org and only
      updated on demand.

      AFAIK, it was last used on Python2 and never on Python3, hence the
      errors you find with it.

      BTW: You appear to have a comma appended to the constant, that doesn't
      belong there:

      +# Placeholder for a missing codepoint
      +MISSING_CODE = -1,
      +

      Perhaps that's causing the second error you are seeing.

    8. abalkin commented on Nov 29, 2010

      @abalkin
      MemberAuthor

      On Mon, Nov 29, 2010 at 1:21 PM, Marc-Andre Lemburg
      <report@bugs.python.org> wrote:
      ..

      BTW: You appear to have a comma appended to the constant, that doesn't
      belong there:

      +# Placeholder for a missing codepoint
      +MISSING_CODE = -1,
      +

      Perhaps that's causing the second error you are seeing.

      No, that comma was a left-over from the attempt to fix the
      mac_chinsimp error. The trace that I reported was generated with
      MISSING_CODE = -1. I am replacing the patch.

      Is it ok to commit a partial fix? It may take longer to fix the mac error.

    9. malemburg commented on Nov 29, 2010

      @malemburg
      Member

      Alexander Belopolsky wrote:

      Alexander Belopolsky <belopolsky@users.sourceforge.net> added the comment:

      On Mon, Nov 29, 2010 at 1:21 PM, Marc-Andre Lemburg
      <report@bugs.python.org> wrote:
      ..
      > BTW: You appear to have a comma appended to the constant, that doesn't
      > belong there:
      >
      > +# Placeholder for a missing codepoint
      > +MISSING_CODE = -1,
      > +
      >
      > Perhaps that's causing the second error you are seeing.

      No, that comma was a left-over from the attempt to fix the
      mac_chinsimp error. The trace that I reported was generated with
      MISSING_CODE = -1. I am replacing the patch.

      Is it ok to commit a partial fix? It may take longer to fix the mac error.

      Sure, we won't need that script anytime soon and if we do, we
      can just as well use the Python2 version.

    10. abalkin commented on Nov 29, 2010

      @abalkin
      MemberAuthor

      On Mon, Nov 29, 2010 at 1:38 PM, Marc-Andre Lemburg
      <report@bugs.python.org> wrote:
      ..

      Sure, we won't need that script anytime soon and if we do, we
      can just as well use the Python2 version.

      That may not be true. I compared 2.7 and py3k versions and the later
      has some new features:

      • unidata_version changed from 5.2.0 to 6.0.0
      • Unihan data is read from zip file
      • added processing of DerivedCoreProperties

      These changes don't affect gencodec.py, but it may be inconvenient to
      run makeunicodedata.py and gencodec.py using different versions of
      Python.

      I'll check that all non-mac encodings are correctly generated before committing.

    11. loewis commented on Nov 29, 2010

      loewismannequin
      Mannequin

      These changes don't affect gencodec.py, but it may be inconvenient to
      run makeunicodedata.py and gencodec.py using different versions of
      Python.

      As MAL explains: these are completely unrelated, independent tools,
      and gencodec isn't run more than once per decade (or so). I only ever
      run makeunicodedata, and I have been using Python 3 to run it.

      The mappings are not supposed to ever change once produced. In
      particular, new versions of Unicode cannot affect them, since the
      existing characters all map fine to existing code points, which will
      not change their meaning per Unicode stability criteria.

    12. abalkin commented on Nov 30, 2010

      @abalkin
      MemberAuthor

      Committed in revision 86891. Keeping open to address Mac issue.

    13. self-assigned this
      on Nov 30, 2010
    14. akuchling commented on Nov 10, 2013

      @akuchling
      Contributor

      For the Mac issue, we could just delete the mapping files before processing them. I've attached a patch that modifies the Makefile.

    15. removed their assignment
      on Jun 29, 2014
    16. vadmium commented on Jan 13, 2015

      @vadmium
      Member

      Here is a new version of Kuchling’s patch. I restored some mapping files which do not give any errors (including the mac_turkish codec, which is actually documented), and removed both readme files.

    17. iritkatriel commented on Nov 24, 2021

      @iritkatriel
      Member

      I don't think Martin's patch has been applied. Is it needed?

    18. transferred this issue fromon Apr 10, 2022
    19. iritkatriel commented on Nov 23, 2023

      @iritkatriel
      Member

      @ned-deily Is there anything left to do here for Mac or can we close it?

    20. added
      pendingThe issue will be closed if no feedback is provided
      on Nov 23, 2023
    21. ned-deily commented on Nov 23, 2023

      @ned-deily
      Member

      I know next to nothing about this other than the mac_* codecs referenced date back decades to classic Mac OS (9 and earlier) and, AFAIK, aren't used today except perhaps in some dusty legacy code. @malemburg, what do you think?

    22. malemburg commented on Nov 24, 2023

      @malemburg
      Member

      I tried to run the script against the MAPPINGS/VENDORS/APPLE/ dir files and still get the TypeError: '<' not supported between instances of 'tuple' and 'int' for some of the files.

      This is apparently a bug in the script which occurs when the mapping files map a single char to multiple code points. Simply removing the sorting fixes the problem, but I have not checked whether the resulting mappings are any good.

      Given that these existing mac_*.py encoding mappings won't change anymore, the script works for those mappings and that we don't need to regenerate those codecs anytime soon, I'd suggest to close the ticket.

    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

      pendingThe issue will be closed if no feedback is providedtopic-unicodetype-bugAn unexpected behavior, bug, or error

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions