Nekmo/telegram-upload

View on GitHub

Showing 30 of 34 total issues

File test_caption_formatter.py has 348 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import sys
import unittest
from pathlib import Path
from unittest.mock import patch, MagicMock, mock_open, call

Severity: Minor
Found in tests/test_caption_formatter.py - About 4 hrs to fix

    File telegram_upload_client.py has 319 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import asyncio
    import hashlib
    import os
    import time
    from typing import Iterable, Optional
    Severity: Minor
    Found in telegram_upload/client/telegram_upload_client.py - About 3 hrs to fix

      TestFilePath has 24 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class TestFilePath(unittest.TestCase):
          """Test the FilePath class."""
      
          def setUp(self) -> None:
              """Set up the test case."""
      Severity: Minor
      Found in tests/test_caption_formatter.py - About 2 hrs to fix

        File caption_formatter.py has 271 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import _string
        import datetime
        import hashlib
        import mimetypes
        import os
        Severity: Minor
        Found in telegram_upload/caption_formatter.py - About 2 hrs to fix

          FileMixin has 23 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class FileMixin:
          
              def _calculate_hash(self, hash_calculator: Any) -> str:
                  with open(str(self), "rb") as f:
                      # Read and update hash string value in blocks
          Severity: Minor
          Found in telegram_upload/caption_formatter.py - About 2 hrs to fix

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

            def upload(files, to, config, delete_on_success, print_file_id, force_file, forward, directories, large_files, caption,
                       no_thumbnail, thumbnail_file, proxy, album, interactive, sort):
                """Upload one or more files to Telegram using your personal account.
                The maximum file size is 2 GiB for free users and 4 GiB for premium accounts.
                By default, they will be saved in your saved messages.
            Severity: Minor
            Found in telegram_upload/management.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 upload has 16 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def upload(files, to, config, delete_on_success, print_file_id, force_file, forward, directories, large_files, caption,
            Severity: Major
            Found in telegram_upload/management.py - About 2 hrs to fix

              Function for_humans has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def for_humans(self) -> str:
                      words = ["year", "day", "hour", "minute", "second"]
              
                      if not self.seconds:
                          return "now"
              Severity: Minor
              Found in telegram_upload/caption_formatter.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_files has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def send_files(self, entity, files: Iterable[File], delete_on_success=False, print_file_id=False,
                                 forward=(), send_as_media: bool = False):
                      has_files = False
                      messages = []
                      for file in files:
              Severity: Minor
              Found in telegram_upload/client/telegram_upload_client.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

              Consider simplifying this complex logical expression.
              Open

                          if (has_func and obj.__func__ in AUTHORIZED_METHODS) or \
                                  (has_self and isinstance(obj.__self__, str) and obj.__name__ in AUTHORIZED_STRING_METHODS) or \
                                  (has_self and isinstance(obj.__self__, datetime.datetime)
                                   and obj.__name__ in AUTHORIZED_DT_METHODS):
                              obj = obj()
              Severity: Critical
              Found in telegram_upload/caption_formatter.py - About 1 hr to fix

                Function start has 9 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def start(
                Severity: Major
                Found in telegram_upload/client/telegram_manager_client.py - About 1 hr to fix

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

                  def get_file_display_name(message):
                      display_name_parts = []
                      is_document = message.document
                      if is_document and message.document.mime_type:
                          display_name_parts.append(message.document.mime_type.split('/')[0])
                  Severity: Minor
                  Found in telegram_upload/management.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_iterator has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_iterator(self) -> Iterator[DownloadFile]:
                          """Get an iterator with the download files. This method applies the join strategy and
                          joins the files after download it.
                          """
                          current_join_strategy: Optional[JoinStrategyBase] = None
                  Severity: Minor
                  Found in telegram_upload/download_files.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_field has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_field(self, field_name: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any:
                          try:
                              if "._" in field_name:
                                  raise TypeError(f'Access to private property in {field_name}')
                              obj, first = super().get_field(field_name, args, kwargs)
                  Severity: Minor
                  Found in telegram_upload/caption_formatter.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 benchmark has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def benchmark(repeats, benchmark, parallel, results_file):
                      client = TelegramManagerClient(default_config())
                      client.start()
                      if benchmark:
                          benchmarks = [BENCHMARKS[benchmark]]
                  Severity: Minor
                  Found in docs/upload_benchmark.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

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

                  def get_file_attributes(file):
                      attrs = []
                      mime = get_file_mime(file)
                      if mime == 'video':
                          metadata = video_metadata(file)
                  Severity: Minor
                  Found in telegram_upload/upload_files.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

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

                  def download(from_, config, delete_on_success, proxy, split_files, interactive):
                  Severity: Minor
                  Found in telegram_upload/management.py - About 45 mins to fix

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

                    def get_video_thumb(file, output=None, size=200):
                        output = output or tempfile.NamedTemporaryFile(suffix='.jpg').name
                        metadata = video_metadata(file)
                        if metadata is None:
                            return
                    Severity: Minor
                    Found in telegram_upload/video.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

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

                        def send_files(self, entity, files: Iterable[File], delete_on_success=False, print_file_id=False,
                    Severity: Minor
                    Found in telegram_upload/client/telegram_upload_client.py - About 45 mins to fix

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

                          def _iter_download_chunk_tasks(self, input_location, part_size, dc_id, msg_data, file_size):
                      Severity: Minor
                      Found in telegram_upload/client/telegram_download_client.py - About 35 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language