Skip to content

valid python in a non-utf-8 encoding reported as a broken file #971

Description

@jshwi

Source files are always read as UTF-8, so valid Python that CPython runs fine is reported as unparseable.

Two cases:

PEP 263 coding cookie — a file declaring another codec cannot be read at all, and surfaces as SIG902 with the critical exit status:

# -*- coding: latin-1 -*-
# café
def function(param: int) -> None:
    """Summary.

    :param param: A description.
    """

UTF-8 BOM — the byte-order mark some editors prepend leaks into the source and surfaces as SIG901 invalid-syntax.

Expected: no error in either case. docsig should follow the Python tokenizer's own rules (tokenize.detect_encoding, which handles both the coding cookie and the BOM) when deciding how to decode a file, so anything CPython can run can be read. Files that genuinely cannot be decoded should still surface as a unicode decode error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions