white = "\033[38;5;255m"
reset = "\033[0;0m"
- if self.path:
- prompt = f"{bolt}[{self.prompt} {white}{self.path}{reset}{bolt}]"
- else:
- prompt = f"{bolt}{self.prompt}"
+ prompt = f"{bolt}[{self.prompt} {white}{self.path}{reset}{bolt}]" if self.path else f"{bolt}{self.prompt}"
return f"{prompt}> {reset}"
def interactive(self) -> None:
# if action is SubParserAction
if isinstance(action, argparse._SubParsersAction): # noqa: SLF001
- subparser: Optional[argparse.ArgumentParser] = action.choices[arg] if arg in action.choices else None
+ subparser: Optional[argparse.ArgumentParser] = action.choices.get(arg, None)
command = get_subparser_command(subparser) if subparser else None
if command and subparser:
current = config
for key in keys[1:-1]:
- if key not in current:
- current[key] = {}
- elif key in current and not isinstance(current[key], dict):
+ if key not in current or key in current and not isinstance(current[key], dict):
current[key] = {}
current = current[key]
if isinstance(source_value, str):
# we do not load global validation context if the path is absolute
# this prevents errors when constructing defaults in the schema
- if source_value.startswith("/"):
- resolve_root = Path("/")
- else:
- resolve_root = get_resolve_root()
+ resolve_root = Path("/") if source_value.startswith("/") else get_resolve_root()
self._raw_value: str = source_value
if self._parents:
# __iter__ for class enum.Flag added in python3.11
# 'for perm in perm_mode:' fails for <=python3.11
- for perm in _PermissionMode:
- if perm in perm_mode:
- if not accessible(perm):
- return False
- return True
+ return all(not (perm in perm_mode and not accessible(perm)) for perm in _PermissionMode)
class ReadableFile(File):
nonlocal original_value
if not original_value_set:
original_value_set = True
- elif original_value == selector(config):
- await orig_func(config, force)
- elif force:
+ elif original_value == selector(config) or force:
await orig_func(config, force)
original_value = selector(config)
if not original_value_set:
original_value_set = True
await orig_func(config, force)
- elif original_value != selector(config):
- await orig_func(config, force)
- elif force:
+ elif original_value != selector(config) or force:
await orig_func(config, force)
original_value = selector(config)
self._timestamp = time.time()
def try_decrease(self) -> None:
- if time.time() - self._timestamp > FIX_COUNTER_DECREASE_INTERVAL_SEC:
- if self._counter > 0:
- logger.info(
- f"Enough time has passed since last detected instability, decreasing fix attempt counter to {self._counter}"
- )
- self._counter -= 1
- self._timestamp = time.time()
+ if time.time() - self._timestamp > FIX_COUNTER_DECREASE_INTERVAL_SEC and self._counter > 0:
+ logger.info(
+ f"Enough time has passed since last detected instability, decreasing fix attempt counter to {self._counter}"
+ )
+ self._counter -= 1
+ self._timestamp = time.time()
def __str__(self) -> str:
return str(self._counter)
return func(_create_untouchable("obj"), source)
raise RuntimeError("Transformation function has wrong number of arguments")
except ValueError as e:
- if len(e.args) > 0 and isinstance(e.args[0], str):
- msg = e.args[0]
- else:
- msg = "Failed to validate value type"
+ msg = e.args[0] if len(e.args) > 0 and isinstance(e.args[0], str) else "Failed to validate value type"
raise DataValidationError(msg, object_path) from e
def object_constructor(self, obj: Any, source: Union["BaseSchema", Dict[Any, Any]], object_path: str) -> None:
return False
annot = get_annotations(cls)
- for name in annot.keys():
- if getattr(self, name) != getattr(o, name):
- return False
-
- return True
+ return all(getattr(self, name) == getattr(o, name) for name in annot)
@classmethod
def json_schema(