GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Report a clean error for files that are not valid UTF-8 by inchang-ing · Pull Request #22056 · python/mypy

Conversation

@inchang-ing

@inchang-ing inchang-ing commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #22055

Since #21996 made single-file batches lazy, files that are not valid UTF-8
crash mypy with an unhandled ValueError: stream did not contain valid UTF-8 raised from the native parser. The eager path (State.get_source)
already converts decode failures into a CompileError with a user-facing
message, but the lazy path introduced by #21996 bypassed that handling.

This PR mirrors the existing handling in State.parse_file_inner: a
ValueError from parsing is converted into a CompileError whose message
also notes that the native parser requires UTF-8 and does not support PEP 263
coding declarations, so users get an actionable error instead of a crash
report:

file.py: error: Cannot decode file: stream did not contain valid UTF-8.
Note: the native parser requires files to be valid UTF-8 and does not support
PEP 263 'coding' declarations.

How tested: new API-level regression test in mypy/test/testapi.py
(writes a latin-1 file, asserts the clean error and exit status 2), and the
crash was reproduced manually against a latin-1 file from Pylint's test suite
before the fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@inchang-ing
Report a clean error for files that are not valid UTF-8
39cb3fa
@github-actions

This comment has been minimized.

Sign in to view
@inchang-ing
Re-trigger CI (build worker connection flake on py314 job)
3c92ad2
@github-actions

github-actions Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core)
- Warning: disabling incremental mode may severely reduce performance
- If this is intentional, delete '.mypy_cache' to suppress this warning
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi

ilevkivskyi commented Sep 29, 2026

Copy link
Copy Markdown
Member

Closing in favor of #22066

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ilevkivskyi ilevkivskyi closed this Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@inchang-ing @ilevkivskyi
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.