flamingo-run/django-cloud-tasks

View on GitHub

Showing 9 of 11 total issues

File task.py has 324 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import abc
import inspect
from dataclasses import dataclass, fields
from datetime import datetime, timedelta, timezone
from functools import lru_cache
Severity: Minor
Found in django_cloud_tasks/tasks/task.py - About 3 hrs to fix

    Function from_headers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def from_headers(cls, headers: dict) -> Self:
            # Available data: https://cloud.google.com/tasks/docs/creating-http-target-tasks#handler
            cloud_tasks_prefix = "X-Cloudtasks-"
            cloud_scheduler_prefix = "X-Cloudscheduler"
    
    
    Severity: Minor
    Found in django_cloud_tasks/tasks/task.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 discard has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def discard(cls, task_id: str | None = None, min_retries: int = 0):
            client = cls._get_tasks_client()
            if task_id:
                task_objects = [client.get_task(queue_name=cls.queue(), task_name=task_id)]
            else:
    Severity: Minor
    Found in django_cloud_tasks/tasks/task.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 initialize_subscribers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize_subscribers(self) -> Tuple[Iterable[str], Iterable[str], Iterable[str]]:
            client = CloudSubscriber()
    
            def _get_subscriptions():
                names = []
    Severity: Minor
    Found in django_cloud_tasks/apps.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 push has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def push(
            cls,
            task_kwargs: dict,
            headers: dict | None = None,
            queue: str | None = None,
    Severity: Minor
    Found in django_cloud_tasks/tasks/task.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 super().default(o)
    Severity: Major
    Found in django_cloud_tasks/serializers.py - About 30 mins to fix

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

          def default(self, o):
              if o is None:
                  return None
              if isinstance(o, datetime):
                  value = assure_tz(o.astimezone())
      Severity: Minor
      Found in django_cloud_tasks/serializers.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 schedule_tasks has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def schedule_tasks(self) -> Tuple[Iterable[str], Iterable[str], Iterable[str]]:
              client = CloudScheduler()
      
              def _get_tasks():
                  names = []
      Severity: Minor
      Found in django_cloud_tasks/apps.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 __eq__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def __eq__(self, other) -> bool:
              if not isinstance(other, TaskMetadata):
                  return False
      
              check_fields = [field.name for field in fields(TaskMetadata)]
      Severity: Minor
      Found in django_cloud_tasks/tasks/task.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

      Severity
      Category
      Status
      Source
      Language