#22055·mypy

`ValueError: stream did not contain valid UTF-8` when checking latin_1 file

Author: correctmostCreated Sep 27, 2026Updated Sep 27, 2026
Labelscrash

Crash Report

Starting with commit 4c5c588a, mypy crashes when checking a file from Pylint's test suite: implicit_str_concat_latin1.py

Are non-UTF-8 files still supported? If not, maybe an error message could help users handle the behavior change.

Traceback

python-traceback
Traceback (most recent call last):
  File ".venv-mypy/bin/mypy", line 6, in <module>
    sys.exit(console_entry())
  File "mypy/mypy/__main__.py", line 16, in console_entry
    main()
  File "mypy/mypy/main.py", line 167, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "mypy/mypy/main.py", line 257, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "mypy/mypy/build.py", line 425, in build
    result = build_inner(
  File "mypy/mypy/build.py", line 540, in build_inner
    graph = dispatch(sources, manager, stdout, connect_threads)
  File "mypy/mypy/build.py", line 4122, in dispatch
    graph = load_graph(sources, manager)
  File "mypy/mypy/build.py", line 4355, in load_graph
    manager.parse_all([state for state in new if state.needs_parse])
  File "mypy/mypy/build.py", line 1089, in parse_all
    parallel_states[0].parse_file()
  File "mypy/mypy/build.py", line 3262, in parse_file
    with self.wrap_context():
  File "/usr/lib/python3.14/contextlib.py", line 162, in __exit__
    self.gen.throw(value)
  File "mypy/mypy/build.py", line 3094, in wrap_context
    yield
  File "mypy/mypy/build.py", line 3270, in parse_file
    self.parse_file_inner(source, raw_data)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "mypy/mypy/build.py", line 3234, in parse_file_inner
    self.tree = self.manager.parse_file(
                ~~~~~~~~~~~~~~~~~~~~~~~^
        self.id, self.xpath, source, options=self.options, raw_data=raw_data
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "mypy/mypy/build.py", line 1282, in parse_file
    tree = parse(source, path, id, self.errors, options=options)
  File "mypy/mypy/parse.py", line 40, in parse
    tree, _, _ = mypy.nativeparse.native_parse(
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        fnam, options, source, skip_function_bodies=strip_function_bodies
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "mypy/mypy/nativeparse.py", line 241, in native_parse
    ) = parse_to_binary_ast(filename, options, source, skip_function_bodies)
        ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mypy/mypy/nativeparse.py", line 300, in parse_to_binary_ast
    ast_bytes, errors, ignores, import_bytes, ast_data = ast_serialize.parse(
                                                         ~~~~~~~~~~~~~~~~~~~^
        filename,
        ^^^^^^^^^
    ...<6 lines>...
        cache_version=5,
        ^^^^^^^^^^^^^^^^
    )
    ^
ValueError: stream did not contain valid UTF-8

To Reproduce

  1. Download implicit_str_concat_latin1.py using GitHub's "Download raw file" button (to avoid charset issues)
  2. Run mypy on the file

Your Environment

  • Mypy version used: 0861bb64
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.14.7
  • Operating system and version: Arch Linux