fepegar/torchio

View on GitHub
src/torchio/utils.py

Summary

Maintainability
D
1 day
Test Coverage

File utils.py has 338 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import annotations

import ast
import gzip
import os
Severity: Minor
Found in src/torchio/utils.py - About 4 hrs to fix

    Function guess_external_viewer has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def guess_external_viewer() -> Optional[Path]:
        """Guess the path to an executable that could be used to visualize images.
    
        Currently, it looks for 1) ITK-SNAP and 2) 3D Slicer. Implemented
        for macOS and Windows.
    Severity: Minor
    Found in src/torchio/utils.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_subjects_from_batch has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_subjects_from_batch(batch: Dict) -> List:
        """Get list of subjects from collated batch.
    
        Args:
            batch: Dictionary generated by a :class:`torch.utils.data.DataLoader`
    Severity: Minor
    Found in src/torchio/utils.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function create_dummy_dataset has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_dummy_dataset(
        num_images: int,
        size_range: Tuple[int, int],
        directory: Optional[TypePath] = None,
        suffix: str = '.nii.gz',
    Severity: Minor
    Found in src/torchio/utils.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function apply_transform_to_file has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def apply_transform_to_file(
    Severity: Minor
    Found in src/torchio/utils.py - About 45 mins to fix

      Function create_dummy_dataset has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def create_dummy_dataset(
      Severity: Minor
      Found in src/torchio/utils.py - About 45 mins to fix

        Function guess_type has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        def guess_type(string: str) -> Any:
            # Adapted from
            # https://www.reddit.com/r/learnpython/comments/4599hl/module_to_guess_type_from_a_string/czw3f5s
            string = string.replace(' ', '')
            result_type: Any
        Severity: Minor
        Found in src/torchio/utils.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Avoid too many return statements within this function.
        Open

                        return slicer_path
        Severity: Major
        Found in src/torchio/utils.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return Path(itk_snap_which)
          Severity: Major
          Found in src/torchio/utils.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return None  # for mypy
            Severity: Major
            Found in src/torchio/utils.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return Path(slicer_which)
              Severity: Major
              Found in src/torchio/utils.py - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status