diff --git a/mypy/nativeparse.py b/mypy/nativeparse.py index 43b3fd6fbeec9..a613e5a45c7c9 100644 --- a/mypy/nativeparse.py +++ b/mypy/nativeparse.py @@ -162,6 +162,8 @@ ) from mypy.util import decode_python_encoding, hash_digest, unnamed_function +AST_SERIALIZE_CACHE_VERSION: Final = 7 + TypeIgnores = list[tuple[int, list[str]]] # There is no way to create reasonable fallbacks at this stage, @@ -419,7 +421,7 @@ def parse_to_binary_ast( platform=options.platform, always_true=options.always_true, always_false=options.always_false, - cache_version=7, + cache_version=AST_SERIALIZE_CACHE_VERSION, ) except ValueError as exc: if source is None: @@ -436,7 +438,7 @@ def parse_to_binary_ast( platform=options.platform, always_true=options.always_true, always_false=options.always_false, - cache_version=5, + cache_version=AST_SERIALIZE_CACHE_VERSION, ) # Compute hash using original non-UTF-8 bytes, so that # incremental mode works correctly. diff --git a/mypy/test/test_nativeparse.py b/mypy/test/test_nativeparse.py index 9ac377365038e..e10889cd52a3a 100644 --- a/mypy/test/test_nativeparse.py +++ b/mypy/test/test_nativeparse.py @@ -290,6 +290,13 @@ def test_latin1(self) -> None: with temp_source(source, encoding="latin1") as fnam: parse_to_binary_ast(fnam, Options()) + def test_latin1_function(self) -> None: + source = "# coding: latin1\nJérôme = False\ndef f(): pass" + with temp_source(source, encoding="latin1") as fnam: + b, _, _, _, _, _, _, _, _ = parse_to_binary_ast(fnam, Options()) + data = ReadBuffer(b) + read_statements(State(Options()), data, read_int(data)) + def test_latin1_broken(self) -> None: source = "# coding: ascii\nJérôme = False" with temp_source(source, encoding="latin1") as fnam: