Skip to content
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

sys.maxunicode value after PEP-393 #57263

Closed
ezio-melotti opened this issue Sep 28, 2011 · 10 comments
Closed

sys.maxunicode value after PEP-393 #57263

ezio-melotti opened this issue Sep 28, 2011 · 10 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-unicode type-bug An unexpected behavior, bug, or error

Comments

@ezio-melotti
Copy link
Member

BPO 13054
Nosy @malemburg, @loewis, @pitrou, @vstinner, @ezio-melotti
Files
  • issue13054.diff
  • issue13054-2.diff: Fix sys.maxunicode checks in the stdlib
  • 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 = 'https://github.com/ezio-melotti'
    closed_at = <Date 2011-10-04.17:47:26.678>
    created_at = <Date 2011-09-28.15:47:34.757>
    labels = ['interpreter-core', 'type-bug', 'expert-unicode']
    title = 'sys.maxunicode value after PEP-393'
    updated_at = <Date 2011-10-04.17:47:26.676>
    user = 'https://github.com/ezio-melotti'

    bugs.python.org fields:

    activity = <Date 2011-10-04.17:47:26.676>
    actor = 'ezio.melotti'
    assignee = 'ezio.melotti'
    closed = True
    closed_date = <Date 2011-10-04.17:47:26.678>
    closer = 'ezio.melotti'
    components = ['Interpreter Core', 'Unicode']
    creation = <Date 2011-09-28.15:47:34.757>
    creator = 'ezio.melotti'
    dependencies = []
    files = ['23251', '23254']
    hgrepos = []
    issue_num = 13054
    keywords = ['patch']
    message_count = 10.0
    messages = ['144568', '144570', '144574', '144578', '144579', '144580', '144611', '144618', '144897', '144914']
    nosy_count = 6.0
    nosy_names = ['lemburg', 'loewis', 'pitrou', 'vstinner', 'ezio.melotti', 'python-dev']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13054'
    versions = ['Python 3.3']

    @ezio-melotti
    Copy link
    Member Author

    Now that PEP-393 is in and the distinction between narrow and wide doesn't exist anymore, the value of sys.maxunicode should always be 0x10FFFF.

    sys.maxunicode currently uses PyUnicode_GetMax (Objects/unicodeobject.c:196) and still returns either 0x10FFFF if Py_UNICODE_WIDE is defined or 0xFFFF if it's not (and that should now mean that it's defined on Linux where wchar_t is 4 bytes, but not on Windows where it's 2 bytes (isn't this backward incompatible? if so it probably deserves another issue)).

    IIUC the difference between narrow and wide is gone for Python users, but it's still there for C users that use the old API, so changing PyUnicode_GetMax will most likely break their code.

    I therefore suggest to set sys.maxunicode to 0x10FFFF and to leave PyUnicode_GetMax as is.

    C users that switch to the new API should stop using PyUnicode_GetMax and it should be added along with the other deprecated functions in PEP-393.
    If sys.maxunicode becomes a constant, it won't be useful to determine if the build is narrow or wide anymore (that won't actually matter anymore, but this was the main use of sys.maxunicode), but it might still be useful to know the value of the highest codepoint. Therefore I think that sys.maxunicode can still stay around without being deprecated (its documentation should be fixed though).

    @ezio-melotti ezio-melotti self-assigned this Sep 28, 2011
    @ezio-melotti ezio-melotti added interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-unicode type-bug An unexpected behavior, bug, or error labels Sep 28, 2011
    @ezio-melotti
    Copy link
    Member Author

    Attached initial patch that sets the value of sys.maxunicode to 0x10FFFF, adds a test, and document the change in both the sys.rst doc and in the 3.3 whatsnew.

    The patch doesn't include any deprecation. If we decide to deprecate something the PEP and possibly the code should be updated.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Sep 28, 2011

    Sounds all fine to me.

    As the PEP specifies, all deprecation will only be on paper for now, not in the code. Adding PyUnicode_GetMax to the list sounds fine to me as well.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 28, 2011

    New changeset 606652491366 by Ezio Melotti in branch 'default':
    bpo-13054: sys.maxunicode is now always 0x10FFFF.
    http://hg.python.org/cpython/rev/606652491366

    @ezio-melotti
    Copy link
    Member Author

    Attached a second patch that fixes checks like:
    if sys.maxunicode == 65535:
    ...

    There are a couple of places (e.g. test_bigmem) where I'm not sure what the best fix is, so I added a couple of XXX in the patch. If you have any suggestion please comment either here on in the review page.

    @ezio-melotti
    Copy link
    Member Author

    I added PyUnicode_GetMax to the list of deprecated functions in PEP-393 in http://hg.python.org/peps/rev/9a154edf18e6.
    (I'm also adding Antoine to the nosy because he might know something about test_bigmem.)

    @vstinner
    Copy link
    Member

    As said on IRC, unicodesize and character_size should be 1 before the test is something like 'x'*1. Or you can just remove this constant, it's not very useful to have a constant equal to 1 :-)

    @pitrou
    Copy link
    Member

    pitrou commented Sep 29, 2011

    I think there's no point in deprecating a function (or data) with a perfectly valid definition.
    As for test_bigmem, better keep character_size hardwired to 1 (if all tests really use only ASCII chars, which I'm not sure they do).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 4, 2011

    New changeset f39b26ca7f3d by Ezio Melotti in branch 'default':
    bpo-13054: fix usage of sys.maxunicode after PEP-393.
    http://hg.python.org/cpython/rev/f39b26ca7f3d

    @ezio-melotti
    Copy link
    Member Author

    The buildbot seems happy, so I'm closing this.
    Antoine already took care of test_bigmem, and Victor opened bpo-13100 for sre_compile.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-unicode type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants