Fix issue with latest mypy (#41363)

This commit is contained in:
Massimiliano Culpo 2023-11-30 20:31:03 +01:00 committed by GitHub
parent d874c6d79c
commit 6ff07c7753
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -206,11 +206,15 @@ def tokenize(text: str) -> Iterator[Token]:
scanner = ALL_TOKENS.scanner(text) # type: ignore[attr-defined] scanner = ALL_TOKENS.scanner(text) # type: ignore[attr-defined]
match: Optional[Match] = None match: Optional[Match] = None
for match in iter(scanner.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( yield Token(
TokenType.__members__[match.lastgroup], # type: ignore[attr-defined] TokenType.__members__[match.lastgroup], match.group(), match.start(), match.end()
match.group(), # type: ignore[attr-defined]
match.start(), # type: ignore[attr-defined]
match.end(), # type: ignore[attr-defined]
) )
if match is None and not text: if match is None and not text: