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

Python 3 gives misleading errors when validating unicode identifiers #67452

Closed
bachmann1234 mannequin opened this issue Jan 18, 2015 · 5 comments
Closed

Python 3 gives misleading errors when validating unicode identifiers #67452

bachmann1234 mannequin opened this issue Jan 18, 2015 · 5 comments
Labels
topic-unicode type-feature A feature request or enhancement

Comments

@bachmann1234
Copy link
Mannequin

bachmann1234 mannequin commented Jan 18, 2015

BPO 23263
Nosy @vstinner, @ezio-melotti, @serhiy-storchaka, @Bachmann1234
Files
  • clarify_unicode_identifier_errors.patch: Patch to provide a different error when a character is simply an invalid start rather than an entirely invalid one
  • 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 2015-03-02.13:39:45.024>
    created_at = <Date 2015-01-18.05:44:41.774>
    labels = ['type-feature', 'expert-unicode']
    title = 'Python 3 gives misleading errors when validating unicode identifiers'
    updated_at = <Date 2015-03-02.13:39:45.022>
    user = 'https://github.com/bachmann1234'

    bugs.python.org fields:

    activity = <Date 2015-03-02.13:39:45.022>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-03-02.13:39:45.024>
    closer = 'vstinner'
    components = ['Unicode']
    creation = <Date 2015-01-18.05:44:41.774>
    creator = 'Matt.Bachmann'
    dependencies = []
    files = ['37755']
    hgrepos = []
    issue_num = 23263
    keywords = ['patch']
    message_count = 5.0
    messages = ['234222', '237027', '237030', '237042', '237043']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'ezio.melotti', 'serhiy.storchaka', 'Matt.Bachmann']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue23263'
    versions = ['Python 3.5']

    @bachmann1234
    Copy link
    Mannequin Author

    bachmann1234 mannequin commented Jan 18, 2015

    PEP-3131 changed the definition of valid identifiers to match this pattern

    <XID_Start> <XID_Continue>* .

    Currently if you have an invalid character in an identifier you get this error

    ☺ = 4
    SyntaxError: invalid character in identifier

    This is fine in most cases. But in some cases the problem is not the character is invalid so much as the character may not be used to START the identifier. One example of this is the "combining grave accent" which is an XID_CONTINUE character but not an XID_START

    So ̀e is an invalid identifier but è is a valid identifier. So the ̀ character is not invalid in all cases.

    The attached patch attempts to clarify this by providing a different error when the start character is invalid.

    >>> ̀e = 4
      File "<stdin>", line 1
        ̀e = 4
         ^
    SyntaxError: invalid start character in identifier
    
    However, if the character is simply not allowed (as it is neither an XID_START or an XID_CONTINUE character) the original error is used.
    >>> ☺smile = 4
      File "<stdin>", line 1
        ☺smile = 4
             ^
    SyntaxError: invalid character in identifier

    @bachmann1234 bachmann1234 mannequin added topic-unicode type-feature A feature request or enhancement labels Jan 18, 2015
    @ezio-melotti
    Copy link
    Member

    While the request is reasonable, the patch seems to touch quite some code.
    Since this is just to improve an error message in a somewhat obscure corner case, I'm not sure it's worth applying it.

    @serhiy-storchaka
    Copy link
    Member

    Agreed with Ezio. Adding 7 new public names just to enhance one rare error message looks too hight cost. I am inclined to left all as is. Original message is not so bad.

    @bachmann1234
    Copy link
    Mannequin Author

    bachmann1234 mannequin commented Mar 2, 2015

    Alrighty. I'll investigate and see if I can cut down the code some. If I can't significantly I'll let the issue die quietly. I agree that it's a pretty nitpick ticket.

    I noticed it while doing some research into unicode and made the patch when I saw how languages like swift handle this case.

    Thanks for looking at it though!

    @vstinner
    Copy link
    Member

    vstinner commented Mar 2, 2015

    The attached patch attempts to clarify this by providing a different error when the start character is invalid.

    I dislike the patch. The error message "invalid character in identifier" is correct. I don't want to modify so much code for a little better error message.

    If you start to use non-ASCII identifier, you are probably already aware that you may get some issues. I close the issue.

    @vstinner vstinner closed this as completed Mar 2, 2015
    @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
    topic-unicode type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants