idlesign/torrentool

View on GitHub
torrentool/torrent.py

Summary

Maintainability
D
2 days
Test Coverage

Torrent has 33 functions (exceeds 20 allowed). Consider refactoring.
Open

class Torrent:
    """Represents a torrent file, and exposes utilities to work with it."""

    def __init__(self, dict_struct: dict = None):
        dict_struct: dict = dict_struct or {'info': {}}
Severity: Minor
Found in torrentool/torrent.py - About 4 hrs to fix

    File torrent.py has 318 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    from calendar import timegm
    from datetime import datetime
    from functools import reduce
    from hashlib import sha1
    from os import walk, sep
    Severity: Minor
    Found in torrentool/torrent.py - About 3 hrs to fix

      Function create_from has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_from(cls, src_path: Union[str, Path]) -> 'Torrent':
              """Returns Torrent object created from a file or a directory.
      
              :param src_path:
      
      
      Severity: Minor
      Found in torrentool/torrent.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 announce_urls has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def announce_urls(self, val: List[str]):
              self._struct['announce'] = ''
              self._struct['announce-list'] = []
      
              def set_single(val):
      Severity: Minor
      Found in torrentool/torrent.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 get_magnet has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_magnet(self, detailed: Union[bool, list, tuple, set] = True) -> str:
              """Returns torrent magnet link, consisting of BTIH (BitTorrent Info Hash) URN
              anr optional other information.
      
              :param detailed:
      Severity: Minor
      Found in torrentool/torrent.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

      Avoid deeply nested control flow statements.
      Open

                              if not isinstance(item, _ITERABLE_TYPES):
                                  item = [item]
                              self._struct['announce-list'].append(item)
      Severity: Major
      Found in torrentool/torrent.py - About 45 mins to fix

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

            def _get_target_files_info(cls, src_path: Path) -> Tuple[List[Tuple[str, int, List[str]]], int]:
                is_dir = src_path.is_dir()
        
                src_path = f'{src_path}'  # Force walk() to return unicode names.
                target_files = []
        Severity: Minor
        Found in torrentool/torrent.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

        There are no issues that match your filters.

        Category
        Status