4848from __future__ import annotations
4949
5050from collections .abc import Sequence
51- from typing import Any , Final , TypeAlias as _TypeAlias
51+ from typing import TYPE_CHECKING , Any , Final , TypeAlias as _TypeAlias
52+
53+ if TYPE_CHECKING :
54+ from mypy .types import SentinelValue
5255
5356from librt .internal import (
5457 ReadBuffer as ReadBuffer ,
6972from mypy_extensions import u8
7073
7174# High-level cache layout format
72- CACHE_VERSION : Final = 10
75+ CACHE_VERSION : Final = 11
7376
7477# Type used internally to represent errors:
7578# (path, line, column, end_line, end_column, severity, message, code)
@@ -308,6 +311,7 @@ def read(cls, data: ReadBuffer) -> CacheMetaEx | None:
308311LITERAL_BYTES : Final [Tag ] = 5
309312LITERAL_FLOAT : Final [Tag ] = 6
310313LITERAL_COMPLEX : Final [Tag ] = 7
314+ LITERAL_SENTINEL : Final [Tag ] = 8
311315
312316# Collections.
313317LIST_GEN : Final [Tag ] = 20
@@ -328,7 +332,7 @@ def read(cls, data: ReadBuffer) -> CacheMetaEx | None:
328332END_TAG : Final [Tag ] = 255
329333
330334
331- def read_literal (data : ReadBuffer , tag : Tag ) -> int | str | bool | float :
335+ def read_literal (data : ReadBuffer , tag : Tag ) -> int | str | bool | float | SentinelValue :
332336 if tag == LITERAL_INT :
333337 return read_int_bare (data )
334338 elif tag == LITERAL_STR :
@@ -339,12 +343,18 @@ def read_literal(data: ReadBuffer, tag: Tag) -> int | str | bool | float:
339343 return True
340344 elif tag == LITERAL_FLOAT :
341345 return read_float_bare (data )
346+ elif tag == LITERAL_SENTINEL :
347+ from mypy .types import SentinelValue as _SentinelValue
348+
349+ return _SentinelValue (read_str_bare (data ), read_str_bare (data ))
342350 assert False , f"Unknown literal tag { tag } "
343351
344352
345353# There is an intentional asymmetry between read and write for literals because
346354# None and/or complex values are only allowed in some contexts but not in others.
347- def write_literal (data : WriteBuffer , value : int | str | bool | float | complex | None ) -> None :
355+ def write_literal (
356+ data : WriteBuffer , value : int | str | bool | float | complex | SentinelValue | None
357+ ) -> None :
348358 if isinstance (value , bool ):
349359 write_bool (data , value )
350360 elif isinstance (value , int ):
@@ -360,8 +370,12 @@ def write_literal(data: WriteBuffer, value: int | str | bool | float | complex |
360370 write_tag (data , LITERAL_COMPLEX )
361371 write_float_bare (data , value .real )
362372 write_float_bare (data , value .imag )
363- else :
373+ elif value is None :
364374 write_tag (data , LITERAL_NONE )
375+ else :
376+ write_tag (data , LITERAL_SENTINEL )
377+ write_str_bare (data , value .fullname )
378+ write_str_bare (data , value .name )
365379
366380
367381def read_int (data : ReadBuffer ) -> int :
0 commit comments