mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
qapi: add must_match helper
Mypy cannot generally understand that these regex functions cannot possibly fail. Add a "must_match" helper that makes this clear for mypy. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210519183951.3946870-10-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
43b1be65f0
commit
e0e8a0ac2e
3 changed files with 16 additions and 11 deletions
|
@ -12,7 +12,7 @@
|
|||
# See the COPYING file in the top-level directory.
|
||||
|
||||
import re
|
||||
from typing import Optional, Sequence
|
||||
from typing import Match, Optional, Sequence
|
||||
|
||||
|
||||
#: Magic string that gets removed along with all space to its right.
|
||||
|
@ -210,3 +210,9 @@ def gen_endif(ifcond: Sequence[str]) -> str:
|
|||
#endif /* %(cond)s */
|
||||
''', cond=ifc)
|
||||
return ret
|
||||
|
||||
|
||||
def must_match(pattern: str, string: str) -> Match[str]:
|
||||
match = re.match(pattern, string)
|
||||
assert match is not None
|
||||
return match
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue