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

compileall.compile_file fails when sys.stdout is redirected to StringIO #88832

Closed
stefanhoelzl mannequin opened this issue Jul 18, 2021 · 5 comments
Closed

compileall.compile_file fails when sys.stdout is redirected to StringIO #88832

stefanhoelzl mannequin opened this issue Jul 18, 2021 · 5 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@stefanhoelzl
Copy link
Mannequin

stefanhoelzl mannequin commented Jul 18, 2021

BPO 44666
Nosy @ambv, @miss-islington, @stefanhoelzl
PRs
  • bpo-44666: Use default encoding as fallback for compile_file #27236
  • [3.10] bpo-44666: Use default encoding as fallback for compile_file (GH-27236) #27488
  • [3.9] bpo-44666: Use default encoding as fallback for compile_file (GH-27236) #27489
  • Files
  • compile_file_bug.py
  • 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 2021-07-30.17:12:54.796>
    created_at = <Date 2021-07-18.08:57:11.563>
    labels = ['3.10', 'library', '3.9', 'type-crash', '3.11']
    title = 'compileall.compile_file fails when sys.stdout is redirected to StringIO'
    updated_at = <Date 2021-07-30.17:13:22.014>
    user = 'https://github.com/stefanhoelzl'

    bugs.python.org fields:

    activity = <Date 2021-07-30.17:13:22.014>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-30.17:12:54.796>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2021-07-18.08:57:11.563>
    creator = 'stefanhoelzl'
    dependencies = []
    files = ['50156']
    hgrepos = []
    issue_num = 44666
    keywords = ['patch']
    message_count = 5.0
    messages = ['397743', '398572', '398576', '398577', '398578']
    nosy_count = 3.0
    nosy_names = ['lukasz.langa', 'miss-islington', 'stefanhoelzl']
    pr_nums = ['27236', '27488', '27489']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue44666'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @stefanhoelzl
    Copy link
    Mannequin Author

    stefanhoelzl mannequin commented Jul 18, 2021

    compile_files tries to escape non-printable characters in error messages by using sys.stdout.encoding
    https://github.com/python/cpython/blob/main/Lib/compileall.py#L256

    when using contextlib.redirect_stdout to redirect stdout to io.StringIO as explained in the documentation
    https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout

    compile_file fails, because io.StringIO has encoding set to None.

    see the attached file to reproduce the issue

    @stefanhoelzl stefanhoelzl mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.10 only security fixes 3.11 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Jul 18, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 30, 2021

    New changeset 80f0707 by Stefan Hoelzl in branch 'main':
    bpo-44666: Use default encoding as fallback for compile_file (GH-27236)
    80f0707

    @ambv
    Copy link
    Contributor

    ambv commented Jul 30, 2021

    New changeset 0db6c14 by Miss Islington (bot) in branch '3.10':
    bpo-44666: Use default encoding as fallback for compile_file (GH-27236) (GH-27488)
    0db6c14

    @ambv
    Copy link
    Contributor

    ambv commented Jul 30, 2021

    New changeset 73240d4 by Miss Islington (bot) in branch '3.9':
    bpo-44666: Use default encoding as fallback for compile_file (GH-27236) (GH-27489)
    73240d4

    @ambv ambv removed 3.7 (EOL) end of life 3.8 only security fixes labels Jul 30, 2021
    @ambv ambv closed this as completed Jul 30, 2021
    @ambv ambv removed 3.7 (EOL) end of life 3.8 only security fixes labels Jul 30, 2021
    @ambv ambv closed this as completed Jul 30, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 30, 2021

    Thanks, Stefan! ✨ 🍰 ✨

    @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
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant