You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The digest_args method has a Cognitive Complexity of 33, exceeding the recommended limit of 15. This makes the method difficult to read, understand, and maintain, especially for new contributors or in scenarios requiring modifications.
The function handles many different responsibilities, such as processing CLI arguments, updating configurations, and handling flags, which contributes to its high complexity. Breaking it into smaller, focused helper methods would significantly improve its readability and maintainability.
Motivation:
Readability: Reducing complexity makes the code easier to understand, especially for new contributors;
Maintainability: Smaller, well-defined methods are easier to test and modify without introducing bugs;
Tool Conformance: Addressing this issue aligns the code with SonarQube's recommended standards and improves overall code quality.
Impact on Existing Code:
The functionality of the digest_args method should remain unchanged.
Existing tests should be updated or added to ensure the refactored method behaves as expected.
Proposed Solution:
Refactor the digest_args method into smaller helper methods, each responsible for a specific aspect of the configuration process. For example in this file _"manim/config/utils.py":
1. Handle Config Files
def _handle_config_files(self, args: argparse.Namespace):
if args.file.suffix == ".cfg":
args.config_file = args.file
if str(args.file) == "-":
self.input_file = args.file
if args.config_file:
self.digest_file(args.config_file)
2. Handle CLI Arguments
def _update_from_args(self, args: argparse.Namespace, keys: List[str]):
for key in keys:
if hasattr(args, key):
attr = getattr(args, key)
if attr is not None:
self[key] = attr
3. Process Flags and Quality
def _process_flags(self, args: argparse.Namespace):
if self["save_last_frame"]:
self["write_to_movie"] = False
nflag = args.from_animation_number
if nflag:
self.from_animation_number = nflag[0]
try:
self.upto_animation_number = nflag[1]
except Exception:
logger.info(
f"No end scene number specified in -n option. Rendering from {nflag[0]} onwards..."
)
self.quality = _determine_quality(getattr(args, "quality", None))
The refactored digest_args method would look like this:
Uh oh!
There was an error while loading. Please reload this page.
Description:
Motivation:
Impact on Existing Code:
Proposed Solution:
Refactor the digest_args method into smaller helper methods, each responsible for a specific aspect of the configuration process. For example in this file _"manim/config/utils.py":
1. Handle Config Files
2. Handle CLI Arguments
3. Process Flags and Quality
The refactored digest_args method would look like this:
References:
The text was updated successfully, but these errors were encountered: