← 输入框|github.com|刷新
Skip to content

Broken encoding modules are silently skipped. #72192

Closed

Description

@ericsnowcurrently
BPO 28005
Nosy @malemburg, @ericsnowcurrently, @zooba

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/zooba'
closed_at = <Date 2016-09-09.15:59:19.672>
created_at = <Date 2016-09-07.18:17:08.667>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = 'Broken encoding modules are silently skipped.'
updated_at = <Date 2016-09-09.15:59:19.670>
user = 'https://github.com/ericsnowcurrently'

bugs.python.org fields:

activity = <Date 2016-09-09.15:59:19.670>
actor = 'steve.dower'
assignee = 'steve.dower'
closed = True
closed_date = <Date 2016-09-09.15:59:19.672>
closer = 'steve.dower'
components = ['Interpreter Core']
creation = <Date 2016-09-07.18:17:08.667>
creator = 'eric.snow'
dependencies = []
files = []
hgrepos = []
issue_num = 28005
keywords = []
message_count = 7.0
messages = ['274856', '274933', '274978', '274983', '275011', '275279', '275325']
nosy_count = 5.0
nosy_names = ['lemburg', 'syeberman', 'python-dev', 'eric.snow', 'steve.dower']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue28005'
versions = ['Python 3.6']

Activity

  1. ericsnowcurrently commented on Sep 7, 2016

    @ericsnowcurrently
    MemberAuthor

    In Lib/encodings/init.py, search_function() looks up an encoding by name. It loads the encoding by importing the corresponding module in the encodings package. If there's an ImportError while importing that module then the encoding gets silently ignored. I noticed this while working on issue bpo-16384.

    While I don't have any direct interest in the matter, I expect that it would be more useful to users if we issued a warning or some other printed message when an encoding is ignored.

  2. python-dev commented on Sep 8, 2016

    python-devmannequin
    Mannequin

    New changeset 2b2e7b39bb68 by Steve Dower in branch 'default':
    Issue bpo-28005: Allow ImportErrors in encoding implementation to propagate.
    https://hg.python.org/cpython/rev/2b2e7b39bb68

  3. self-assigned this
    on Sep 8, 2016
  4. malemburg commented on Sep 8, 2016

    @malemburg
    Member

    Steve, this is not a correct patch. The purpose of skipping ImportErrors is to give other search functions a chance to find and provide a working codec. Your patch causes this to break.

  5. malemburg commented on Sep 8, 2016

    @malemburg
    Member

    Thinking about this some, we could go ahead and document somewhere that if a codec wants to tell the search function that it cannot work due to some missing dependency, it will have to raise an ImportError from the codec module level (instead of just lettering ImportError bubble up), possibly reraising the error to assure this.

  6. zooba commented on Sep 8, 2016

    @zooba
    Member

    Is it deliberate that inner import errors should be treated as if the codec is missing? Another search function isn't going to help in that case unless it finds the same encoding in another place. I didn't see any evidence of that, and apparently neither did Eric (but I was bitten by a misspelt import within my new encodings/oem.py giving a confusing message).

    I don't think any encoding modules in the stdlib should fail to import. This change ensures that we hear about it if they do fail.

  7. malemburg commented on Sep 9, 2016

    @malemburg
    Member

    Yes, that's intended. See e.g. the mbcs codec.

    If a search function gets an ImportError, it interprets this as "codec is not available/working", and then gives other search functions a chance to find a working one.

  8. zooba commented on Sep 9, 2016

    @zooba
    Member

    I reverted the change but wrote the wrong issue number. Also added a comment so the next person to encounter this realises it is the correct behaviour.

    New changeset 4e80a157ea66 by Steve Dower in branch 'default':
    Revert bpo-27959: ImportError within an encoding module should also skip the encoding
    https://hg.python.org/cpython/rev/4e80a157ea66

  9. 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

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions