diff --git a/muppet/puppet/format/parser.py b/muppet/puppet/format/parser.py index 552483b004e8c3fc6202b3828322e8f3e71feb2f..42357926339834e277fafec44d4269b48e7a7c01 100644 --- a/muppet/puppet/format/parser.py +++ b/muppet/puppet/format/parser.py @@ -85,6 +85,7 @@ from typing import ( ) from dataclasses import dataclass +import sys ws = name('ws', tag('ws', many(line_comment('#') | space))) @@ -92,19 +93,18 @@ ws = name('ws', tag('ws', many(line_comment('#') | space))) F = TypeVar('F', bound=Callable[..., object]) -# TODO replace this decorator with -# from typing import override -# once the target python version is changed to 3.12 +if sys.version_info >= (3, 12): + from typing import override +else: + def override(f: F) -> F: + """ + Return function unchanged. -def override(f: F) -> F: - """ - Return function unchanged. - - Placeholder @override annotator if the actual annotation isn't - implemented in the current python version. - """ - return f + Placeholder @override annotator if the actual annotation isn't + implemented in the current python version. + """ + return f logger = logging.getLogger(__name__) @@ -318,7 +318,7 @@ class ParserFormatter(Serializer[ParseDirective]): Note that the delimiting "${" and "}" should be handled outside this procedure. """ - parser = ws + parser: ParseDirective = ws match item: case PuppetAccess(PuppetVar(name), _): parser &= optional(s('$')) & name