bel/lang/ast.py

Summary

Maintainability
F
1 wk
Test Coverage

File ast.py has 1101 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# -*- coding: utf-8 -*-


# Standard Library
Severity: Major
Found in bel/lang/ast.py - About 2 days to fix

    Function validate_function has a Cognitive Complexity of 86 (exceeds 5 allowed). Consider refactoring.
    Open

    def validate_function(fn: Function, errors: List[ValidationError] = None) -> List[ValidationError]:
        """Validate function"""
    
        # logger.debug(f"Validating function name {fn.name}, len: {len(fn.args)}")
    
    
    Severity: Minor
    Found in bel/lang/ast.py - About 1 day 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 parse has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse(self):
            """Assemble parsed component from Assertion string into AST"""
    
            self.parse_info = ParseInfo(self.assertion)
    
    
    Severity: Minor
    Found in bel/lang/ast.py - About 6 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 sort_function_args has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

    def sort_function_args(fn: Function):
        """Add sort tuple values to function arguments for canonicalization and sort function arguments"""
    
        signatures = fn.function_signature["signatures"]
    
    
    Severity: Minor
    Found in bel/lang/ast.py - About 6 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 __init__ has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(
            self,
            assertion: AssertionStr = None,
            subject: Optional[Function] = None,
            relation: Optional[Relation] = None,
    Severity: Minor
    Found in bel/lang/ast.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

    Consider simplifying this complex logical expression.
    Open

            if len(self.args) == 1 and self.args[0].type == "Function":
                self.subject = self.args[0]
            # Normal SRO BEL assertion
            elif (
                len(self.args) == 3
    Severity: Critical
    Found in bel/lang/ast.py - About 2 hrs to fix

      Function validate has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate(self, errors: List[ValidationError] = None):
              """Validate BEL Function"""
      
              if errors is None:
                  errors = []
      Severity: Minor
      Found in bel/lang/ast.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 orthologizable has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def orthologizable(self, species_key: Key) -> Optional[bool]:
              """Is this Assertion fully orthologizable?
      
              Is it possible to orthologize every gene/protein/RNA NSArg to the target species?
              """
      Severity: Minor
      Found in bel/lang/ast.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 orthologizable has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def orthologizable(self, species_key: Key):
              """Is this Assertion fully orthologizable?
      
              This method will detect if the orthologization will result
              in a partially orthologized Assertion.
      Severity: Minor
      Found in bel/lang/ast.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 subcomponents has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def subcomponents(self, subcomponents=None):
              """Generate subcomponents of the BEL subject or object
      
              Args:
                  AST
      Severity: Minor
      Found in bel/lang/ast.py - About 55 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

      Function check_str_arg has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def check_str_arg(value: str, check_values: List[str]) -> Optional[str]:
          """Check StrArg value"""
      
          regex_flag = False
          for check_value in check_values:
      Severity: Minor
      Found in bel/lang/ast.py - About 55 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

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

          def __init__(
      Severity: Minor
      Found in bel/lang/ast.py - About 45 mins to fix

        Function subcomponents has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def subcomponents(self, subcomponents=None):
                """Generate subcomponents of the BEL subject or object
        
                Args:
                    AST
        Severity: Minor
        Found in bel/lang/ast.py - About 45 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

        Consider simplifying this complex logical expression.
        Open

                if fn_arg.type == "Function" and fn_arg.name not in opt_and_mult_args:
                    errors.append(
                        ValidationError(
                            type="Assertion",
                            severity="Error",
        Severity: Major
        Found in bel/lang/ast.py - About 40 mins to fix

          Consider simplifying this complex logical expression.
          Open

                  if self.subject or self.relation or self.object:
                      if self.relation and not self.object:
                          msg = "Missing Assertion Object"
                          self.errors.append(ValidationError(type="Assertion", severity="Error", msg=msg))
                      elif self.object and (not self.subject or not self.relation):
          Severity: Major
          Found in bel/lang/ast.py - About 40 mins to fix

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

                def decanonicalize(
                    self,
                    canonical_targets: Mapping[str, List[str]] = settings.BEL_CANONICALIZE,
                    decanonical_targets: Mapping[str, List[str]] = settings.BEL_DECANONICALIZE,
                ):
            Severity: Minor
            Found in bel/lang/ast.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

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

                def get_orthologs(
                    self,
                    orthologs: List[dict] = None,
                    orthologize_targets_keys: List[Key] = None,
                ):
            Severity: Minor
            Found in bel/lang/ast.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

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

                def get_species_keys(self, species_keys: List[str] = None):
                    """Collect species associated with NSArgs
            
                    Can have multiple species related to single Assertion
                    """
            Severity: Minor
            Found in bel/lang/ast.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

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

                def decanonicalize(
                    self,
                    canonical_targets: Mapping[str, List[str]] = settings.BEL_CANONICALIZE,
                    decanonical_targets: Mapping[str, List[str]] = settings.BEL_DECANONICALIZE,
                ):
            Severity: Minor
            Found in bel/lang/ast.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

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

                def canonicalize(
                    self,
                    canonical_targets: Mapping[str, List[str]] = settings.BEL_CANONICALIZE,
                    decanonical_targets: Mapping[str, List[str]] = settings.BEL_DECANONICALIZE,
                ):
            Severity: Minor
            Found in bel/lang/ast.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

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

                def canonicalize(
                    self,
                    canonical_targets: Mapping[str, List[str]] = settings.BEL_CANONICALIZE,
                    decanonical_targets: Mapping[str, List[str]] = settings.BEL_DECANONICALIZE,
                ):
            Severity: Minor
            Found in bel/lang/ast.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

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

                def get_species_keys(self, species_keys: List[str] = None):
                    """Collect species associated with NSArgs
            
                    Can have multiple species related to single Assertion
                    """
            Severity: Minor
            Found in bel/lang/ast.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

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

                def get_orthologs(
                    self, orthologs: List[dict] = None, orthologize_targets_keys: List[Key] = None
                ):
                    """Collect orthologs associated with NSArgs"""
            
            
            Severity: Minor
            Found in bel/lang/ast.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

            Function validate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def validate(self):
                    """Validate BEL Assertion"""
            
                    # Process AST top-level args or Function args
                    if hasattr(self, "args"):
            Severity: Minor
            Found in bel/lang/ast.py - About 25 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

            Function to_string has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def to_string(self, fmt: str = "medium") -> str:
                    """Convert AST object to string
            
                    Args:
                        fmt (str): short, medium, long formatted BEL statements
            Severity: Minor
            Found in bel/lang/ast.py - About 25 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

            Function orthologize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def orthologize(self, species_key: Key):
                    """Orthologize any orthologizable element
            
                    Run orthologizable() method first to confirm that entire Assertion is
                    orthologizable.
            Severity: Minor
            Found in bel/lang/ast.py - About 25 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

            There are no issues that match your filters.

            Category
            Status