From 6ff07c7753781b80bfa4a94151506176b7350364 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Thu, 30 Nov 2023 20:31:03 +0100 Subject: Fix issue with latest mypy (#41363) --- lib/spack/spack/parser.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/parser.py b/lib/spack/spack/parser.py index c69918b419..b0a8d8ad83 100644 --- a/lib/spack/spack/parser.py +++ b/lib/spack/spack/parser.py @@ -206,11 +206,15 @@ def tokenize(text: str) -> Iterator[Token]: scanner = ALL_TOKENS.scanner(text) # type: ignore[attr-defined] match: Optional[Match] = None for match in iter(scanner.match, None): + # The following two assertions are to help mypy + msg = ( + "unexpected value encountered during parsing. Please submit a bug report " + "at https://github.com/spack/spack/issues/new/choose" + ) + assert match is not None, msg + assert match.lastgroup is not None, msg yield Token( - TokenType.__members__[match.lastgroup], # type: ignore[attr-defined] - match.group(), # type: ignore[attr-defined] - match.start(), # type: ignore[attr-defined] - match.end(), # type: ignore[attr-defined] + TokenType.__members__[match.lastgroup], match.group(), match.start(), match.end() ) if match is None and not text: -- cgit v1.2.3-70-g09d2