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

Misleading exception from unicode.__contains__ #44711

Closed
bulbjh mannequin opened this issue Mar 13, 2007 · 3 comments
Closed

Misleading exception from unicode.__contains__ #44711

bulbjh mannequin opened this issue Mar 13, 2007 · 3 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@bulbjh
Copy link
Mannequin

bulbjh mannequin commented Mar 13, 2007

BPO 1680159
Nosy @malemburg, @bitdancer
Files
  • Issue1680159.patch: test and patch
  • 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/malemburg'
    closed_at = <Date 2009-12-14.18:13:19.430>
    created_at = <Date 2007-03-13.20:33:15.000>
    labels = ['interpreter-core', 'type-bug']
    title = 'Misleading exception from unicode.__contains__'
    updated_at = <Date 2009-12-14.18:13:19.428>
    user = 'https://bugs.python.org/bulbjh'

    bugs.python.org fields:

    activity = <Date 2009-12-14.18:13:19.428>
    actor = 'r.david.murray'
    assignee = 'lemburg'
    closed = True
    closed_date = <Date 2009-12-14.18:13:19.430>
    closer = 'r.david.murray'
    components = ['Interpreter Core']
    creation = <Date 2007-03-13.20:33:15.000>
    creator = 'bulbjh'
    dependencies = []
    files = ['13609']
    hgrepos = []
    issue_num = 1680159
    keywords = ['patch']
    message_count = 3.0
    messages = ['31513', '85370', '96381']
    nosy_count = 3.0
    nosy_names = ['lemburg', 'bulbjh', 'r.david.murray']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1680159'
    versions = ['Python 2.7']

    @bulbjh
    Copy link
    Mannequin Author

    bulbjh mannequin commented Mar 13, 2007

    Hello Folks,

    unicode.__contains__ throws:

    >>> '\xff' in u'foo'
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'in <string>' requires string as left operand

    while:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

    would be more helpful, because that's what really fails there. The exception it throws now does not indicate that unicode is involved.

    (tried this with 2.4.4 and 2.5.0 and happens in both)

    @bulbjh bulbjh mannequin added the topic-unicode label Mar 13, 2007
    @bulbjh bulbjh mannequin assigned malemburg Mar 13, 2007
    @bulbjh bulbjh mannequin added the topic-unicode label Mar 13, 2007
    @bulbjh bulbjh mannequin assigned malemburg Mar 13, 2007
    @bitdancer
    Copy link
    Member

    Still gives the same message in 2.7a0. Looks to be simple enough to
    fix: just stop masking the UnicodeDecode and TypeError messages produced
    by the PyUnicode_FromObject call in the PyUnicode_Contains method. Test
    and patch attached. If you have no objection, Mark, I'll apply it.

    @bitdancer bitdancer added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error and removed topic-unicode labels Apr 4, 2009
    @bitdancer
    Copy link
    Member

    Committed in r76831. (I changed the test assertion to check
    specifically for UnicodeDecodeError.)

    @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) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants