airbnb/superset

View on GitHub
superset/utils/core.py

Summary

Maintainability
F
1 wk
Test Coverage

File core.py has 1496 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
Severity: Major
Found in superset/utils/core.py - About 3 days to fix

    Function merge_extra_filters has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
    Open

    def merge_extra_filters(form_data: dict[str, Any]) -> None:
        # extra_filters are temporary/contextual filters (using the legacy constructs)
        # that are external to the slice definition. We use those for dynamic
        # interactive filters.
        # Note extra_filters only support simple filters.
    Severity: Minor
    Found in superset/utils/core.py - About 7 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 merge_extra_form_data has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def merge_extra_form_data(form_data: dict[str, Any]) -> None:
        """
        Merge extra form data (appends and overrides) into the main payload
        and add applied time extras to the payload.
        """
    Severity: Minor
    Found in superset/utils/core.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_metric_name has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_metric_name(metric: Metric, verbose_map: dict[str, Any] | None = None) -> str:
        """
        Extract label from metric
    
        :param metric: object to extract label from
    Severity: Minor
    Found in superset/utils/core.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 extract_dataframe_dtypes has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def extract_dataframe_dtypes(
        df: pd.DataFrame,
        datasource: BaseDatasource | Query | None = None,
    ) -> list[GenericDataType]:
        """Serialize pandas/numpy dtypes to generic types"""
    Severity: Minor
    Found in superset/utils/core.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 split_adhoc_filters_into_base_filters has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def split_adhoc_filters_into_base_filters(  # pylint: disable=invalid-name
        form_data: FormData,
    ) -> None:
        """
        Mutates form data to restructure the adhoc filters in the form of the three base
    Severity: Minor
    Found in superset/utils/core.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 send_email_smtp has 14 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def send_email_smtp(  # pylint: disable=invalid-name,too-many-arguments,too-many-locals
    Severity: Major
    Found in superset/utils/core.py - About 1 hr to fix

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

      def normalize_dttm_col(
          df: pd.DataFrame,
          dttm_cols: tuple[DateColumn, ...] = tuple(),
      ) -> None:
          for _col in dttm_cols:
      Severity: Minor
      Found in superset/utils/core.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 get_time_filter_status has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_time_filter_status(
          datasource: BaseDatasource,
          applied_time_extras: dict[str, str],
      ) -> tuple[list[dict[str, str]], list[dict[str, str]]]:
          temporal_columns: set[Any] = {
      Severity: Minor
      Found in superset/utils/core.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 send_email_smtp has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def send_email_smtp(  # pylint: disable=invalid-name,too-many-arguments,too-many-locals
          to: str,
          subject: str,
          html_content: str,
          config: dict[str, Any],
      Severity: Minor
      Found in superset/utils/core.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 base_json_conv has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def base_json_conv(obj: Any) -> Any:
          """
          Tries to convert additional types to JSON compatible forms.
      
          :param obj: The serializable object
      Severity: Minor
      Found in superset/utils/core.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 split has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def split(
          string: str, delimiter: str = " ", quote: str = '"', escaped_quote: str = r"\""
      ) -> Iterator[str]:
          """
          A split function that is aware of quotes and parentheses.
      Severity: Minor
      Found in superset/utils/core.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 convert_legacy_filters_into_adhoc has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def convert_legacy_filters_into_adhoc(  # pylint: disable=invalid-name
          form_data: FormData,
      ) -> None:
          if not form_data.get("adhoc_filters"):
              adhoc_filters: list[AdhocFilterClause] = []
      Severity: Minor
      Found in superset/utils/core.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 pessimistic_connection_handling has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def pessimistic_connection_handling(some_engine: Engine) -> None:
          @event.listens_for(some_engine, "engine_connect")
          def ping_connection(connection: Connection, branch: bool) -> None:
              if branch:
                  # 'branch' refers to a sub-connection of a connection,
      Severity: Minor
      Found in superset/utils/core.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

      Avoid deeply nested control flow statements.
      Open

                          if isinstance(filtr["val"], list):
                              if isinstance(existing_filters[filter_key], list):
                                  # Add filters for unequal lists
                                  # order doesn't matter
                                  if set(existing_filters[filter_key]) != set(filtr["val"]):
      Severity: Major
      Found in superset/utils/core.py - About 45 mins to fix

        Function send_mime_email has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def send_mime_email(
        Severity: Minor
        Found in superset/utils/core.py - About 35 mins to fix

          Function generic_find_fk_constraint_names has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def generic_find_fk_constraint_names(  # pylint: disable=invalid-name
          Severity: Minor
          Found in superset/utils/core.py - About 35 mins to fix

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

            def get_column_name(column: Column, verbose_map: dict[str, Any] | None = None) -> str:
                """
                Extract label from column
            
                :param column: object to extract label from
            Severity: Minor
            Found in superset/utils/core.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 str(obj)
            Severity: Major
            Found in superset/utils/core.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return False
              Severity: Major
              Found in superset/utils/core.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return format_timedelta(obj)
                Severity: Major
                Found in superset/utils/core.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return obj.decode("utf-8")
                  Severity: Major
                  Found in superset/utils/core.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return "[bytes]"
                    Severity: Major
                    Found in superset/utils/core.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return None
                      Severity: Major
                      Found in superset/utils/core.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return verbose_map.get(metric, metric)
                        Severity: Major
                        Found in superset/utils/core.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return float(obj)
                          Severity: Major
                          Found in superset/utils/core.py - About 30 mins to fix

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

                            def override_user(user: User | None, force: bool = True) -> Iterator[Any]:
                                """
                                Temporarily override the current user per `flask.g` with the specified user.
                            
                                Sometimes, often in the context of async Celery tasks, it is useful to switch the
                            Severity: Minor
                            Found in superset/utils/core.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 send_mime_email has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                            def send_mime_email(
                                e_from: str,
                                e_to: list[str],
                                mime_msg: MIMEMultipart,
                                config: dict[str, Any],
                            Severity: Minor
                            Found in superset/utils/core.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