diff --git a/mmengine/config/config.py b/mmengine/config/config.py index f636cc81..316ac65d 100644 --- a/mmengine/config/config.py +++ b/mmengine/config/config.py @@ -17,6 +17,7 @@ from contextlib import contextmanager from pathlib import Path from typing import Any, Optional, Sequence, Tuple, Union +import yapf from addict import Dict from rich.console import Console from rich.text import Text @@ -1472,8 +1473,11 @@ class Config: blank_line_before_nested_class_or_def=True, split_before_expression_after_opening_paren=True) try: - text, _ = FormatCode( - text, style_config=yapf_style, verify=True) + if digit_version(yapf.__version__) >= digit_version('0.40.2'): + text, _ = FormatCode(text, style_config=yapf_style) + else: + text, _ = FormatCode( + text, style_config=yapf_style, verify=True) except: # noqa: E722 raise SyntaxError('Failed to format the config file, please ' f'check the syntax of: \n{text}')