fossasia/knittingpattern

View on GitHub

Showing 50 of 166 total issues

File Instruction.py has 469 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Knitting patterns consist of instructions.

The :class:`instructions <Instruction>`. that are used in the
:class:`knitting patterns <KnittingPattern>` can be foudn in this module.
They have certain attributes in common.
Severity: Minor
Found in knittingpattern/Instruction.py - About 7 hrs to fix

    Function _set_fills_in_color_layer has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

        def _set_fills_in_color_layer(self, svg_string, color):
            """replaces fill colors in ``<g inkscape:label="color"
            inkscape:groupmode="layer">`` with :paramref:`color`
    
            :param color: a color fill the objects in the layer with
    Severity: Minor
    Found in knittingpattern/convert/InstructionToSVG.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

    TestAddAndRemoveMeshes has 41 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class TestAddAndRemoveMeshes(BaseTest):
        """take away and add meshes at the right and left."""
        FILE = "add and remove meshes.json"
        SIZES = [(1, 1)] * 17
        COORDINATES = [
    Severity: Minor
    Found in knittingpattern/convert/test/test_layout.py - About 5 hrs to fix

      File Mesh.py has 391 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      """This module contains the meshes of the knit work."""
      from abc import ABCMeta, abstractmethod
      
      
      class Mesh(metaclass=ABCMeta):
      Severity: Minor
      Found in knittingpattern/Mesh.py - About 5 hrs to fix

        Mesh has 34 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Mesh(metaclass=ABCMeta):
        
            """A mesh that is either consumed or produced by an instruction.
        
            .. code:: python
        Severity: Minor
        Found in knittingpattern/Mesh.py - About 4 hrs to fix

          Cyclomatic complexity is too high in method _set_fills_in_color_layer. (15)
          Open

              def _set_fills_in_color_layer(self, svg_string, color):
                  """replaces fill colors in ``<g inkscape:label="color"
                  inkscape:groupmode="layer">`` with :paramref:`color`
          
                  :param color: a color fill the objects in the layer with

          Cyclomatic Complexity

          Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

          Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

          Construct Effect on CC Reasoning
          if +1 An if statement is a single decision.
          elif +1 The elif statement adds another decision.
          else +0 The else statement does not cause a new decision. The decision is at the if.
          for +1 There is a decision at the start of the loop.
          while +1 There is a decision at the while statement.
          except +1 Each except branch adds a new conditional path of execution.
          finally +0 The finally block is unconditionally executed.
          with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
          assert +1 The assert statement internally roughly equals a conditional statement.
          Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
          Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

          Source: http://radon.readthedocs.org/en/latest/intro.html

          InstructionInRow has 27 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class InstructionInRow(Instruction):
          
              """Instructions can be placed in rows.
          
              Then, they have additional attributes and properties.
          Severity: Minor
          Found in knittingpattern/Instruction.py - About 3 hrs to fix

            Cyclomatic complexity is too high in method test_disconnected_from. (14)
            Open

                def test_disconnected_from(self, connections, meshes):
                    """Test all the meshes that are disconnected from each other."""
                    for m1 in meshes:
                        assert m1 == m1
                        for m2 in meshes:

            Cyclomatic Complexity

            Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

            Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

            Construct Effect on CC Reasoning
            if +1 An if statement is a single decision.
            elif +1 The elif statement adds another decision.
            else +0 The else statement does not cause a new decision. The decision is at the if.
            for +1 There is a decision at the start of the loop.
            while +1 There is a decision at the while statement.
            except +1 Each except branch adds a new conditional path of execution.
            finally +0 The finally block is unconditionally executed.
            with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
            assert +1 The assert statement internally roughly equals a conditional statement.
            Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
            Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

            Source: http://radon.readthedocs.org/en/latest/intro.html

            Cyclomatic complexity is too high in function test_skp_consumed_meshes_from_row1. (14)
            Open

            def test_skp_consumed_meshes_from_row1(skp, row1, row2):

            Cyclomatic Complexity

            Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

            Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

            Construct Effect on CC Reasoning
            if +1 An if statement is a single decision.
            elif +1 The elif statement adds another decision.
            else +0 The else statement does not cause a new decision. The decision is at the if.
            for +1 There is a decision at the start of the loop.
            while +1 There is a decision at the while statement.
            except +1 Each except branch adds a new conditional path of execution.
            finally +0 The finally block is unconditionally executed.
            with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
            assert +1 The assert statement internally roughly equals a conditional statement.
            Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
            Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

            Source: http://radon.readthedocs.org/en/latest/intro.html

            File Layout.py has 295 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            """Map ``(x, y)`` coordinates to instructions
            
            """
            from itertools import chain
            from collections import namedtuple
            Severity: Minor
            Found in knittingpattern/convert/Layout.py - About 3 hrs to fix

              Cyclomatic complexity is too high in function test_remove_a_connection. (10)
              Open

              def test_remove_a_connection(row1, row2, mesh11p, mesh21c, disconnect):
                  disconnect_meshes(mesh11p, mesh21c, disconnect)
                  assert mesh11p.is_produced()
                  assert not mesh11p.is_consumed()
                  assert mesh11p.producing_row == row1

              Cyclomatic Complexity

              Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

              Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

              Construct Effect on CC Reasoning
              if +1 An if statement is a single decision.
              elif +1 The elif statement adds another decision.
              else +0 The else statement does not cause a new decision. The decision is at the if.
              for +1 There is a decision at the start of the loop.
              while +1 There is a decision at the while statement.
              except +1 Each except branch adds a new conditional path of execution.
              finally +0 The finally block is unconditionally executed.
              with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
              assert +1 The assert statement internally roughly equals a conditional statement.
              Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
              Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

              Source: http://radon.readthedocs.org/en/latest/intro.html

              Cyclomatic complexity is too high in function walk. (9)
              Open

              def walk(knitting_pattern):
                  """Walk the knitting pattern in a right-to-left fashion.
              
                  :return: an iterable to walk the rows
                  :rtype: list
              Severity: Minor
              Found in knittingpattern/walk.py by radon

              Cyclomatic Complexity

              Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

              Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

              Construct Effect on CC Reasoning
              if +1 An if statement is a single decision.
              elif +1 The elif statement adds another decision.
              else +0 The else statement does not cause a new decision. The decision is at the if.
              for +1 There is a decision at the start of the loop.
              while +1 There is a decision at the while statement.
              except +1 Each except branch adds a new conditional path of execution.
              finally +0 The finally block is unconditionally executed.
              with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
              assert +1 The assert statement internally roughly equals a conditional statement.
              Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
              Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

              Source: http://radon.readthedocs.org/en/latest/intro.html

              Parser has 22 functions (exceeds 20 allowed). Consider refactoring.
              Open

              class Parser(object):
              
                  """Parses a knitting pattern set and anything in it."""
              
                  def __init__(self, specification):
              Severity: Minor
              Found in knittingpattern/Parser.py - About 2 hrs to fix

                File test_layout.py has 262 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                """Test the layout of knitting patterns."""
                from test_convert import fixture
                import os
                from knittingpattern.convert.Layout import GridLayout, InstructionInGrid
                from knittingpattern import load_from_relative_file
                Severity: Minor
                Found in knittingpattern/convert/test/test_layout.py - About 2 hrs to fix

                  Cyclomatic complexity is too high in function test_replace_a_connection. (8)
                  Open

                  def test_replace_a_connection(disconnect, connect, mesh21p, mesh31c, mesh12p,

                  Cyclomatic Complexity

                  Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

                  Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

                  Construct Effect on CC Reasoning
                  if +1 An if statement is a single decision.
                  elif +1 The elif statement adds another decision.
                  else +0 The else statement does not cause a new decision. The decision is at the if.
                  for +1 There is a decision at the start of the loop.
                  while +1 There is a decision at the while statement.
                  except +1 Each except branch adds a new conditional path of execution.
                  finally +0 The finally block is unconditionally executed.
                  with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
                  assert +1 The assert statement internally roughly equals a conditional statement.
                  Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
                  Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

                  Source: http://radon.readthedocs.org/en/latest/intro.html

                  Cyclomatic complexity is too high in function test_create_new_connection. (7)
                  Open

                  def test_create_new_connection(mesh31p, mesh12c, connect, row1, row3):

                  Cyclomatic Complexity

                  Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

                  Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

                  Construct Effect on CC Reasoning
                  if +1 An if statement is a single decision.
                  elif +1 The elif statement adds another decision.
                  else +0 The else statement does not cause a new decision. The decision is at the if.
                  for +1 There is a decision at the start of the loop.
                  while +1 There is a decision at the while statement.
                  except +1 Each except branch adds a new conditional path of execution.
                  finally +0 The finally block is unconditionally executed.
                  with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
                  assert +1 The assert statement internally roughly equals a conditional statement.
                  Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
                  Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

                  Source: http://radon.readthedocs.org/en/latest/intro.html

                  Cyclomatic complexity is too high in method insert_defs. (7)
                  Open

                      def insert_defs(self, defs):
                          """Adds the defs to the SVG structure.
                  
                          :param defs: a list of SVG dictionaries, which contain the defs,
                            which should be added to the SVG structure.
                  Severity: Minor
                  Found in knittingpattern/convert/SVGBuilder.py by radon

                  Cyclomatic Complexity

                  Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

                  Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

                  Construct Effect on CC Reasoning
                  if +1 An if statement is a single decision.
                  elif +1 The elif statement adds another decision.
                  else +0 The else statement does not cause a new decision. The decision is at the if.
                  for +1 There is a decision at the start of the loop.
                  while +1 There is a decision at the while statement.
                  except +1 Each except branch adds a new conditional path of execution.
                  finally +0 The finally block is unconditionally executed.
                  with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
                  assert +1 The assert statement internally roughly equals a conditional statement.
                  Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
                  Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

                  Source: http://radon.readthedocs.org/en/latest/intro.html

                  Function test_disconnected_from has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def test_disconnected_from(self, connections, meshes):
                          """Test all the meshes that are disconnected from each other."""
                          for m1 in meshes:
                              assert m1 == m1
                              for m2 in meshes:
                  Severity: Minor
                  Found in knittingpattern/test/test_change_row_mapping.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

                  Cyclomatic complexity is too high in class TestSmallCafe. (6)
                  Open

                  class TestSmallCafe(BaseTest):
                      """This test tests the negative expansion of rows.
                  
                      If you start expanding in the middle, this tests that all rows are
                      included.

                  Cyclomatic Complexity

                  Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

                  Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

                  Construct Effect on CC Reasoning
                  if +1 An if statement is a single decision.
                  elif +1 The elif statement adds another decision.
                  else +0 The else statement does not cause a new decision. The decision is at the if.
                  for +1 There is a decision at the start of the loop.
                  while +1 There is a decision at the while statement.
                  except +1 Each except branch adds a new conditional path of execution.
                  finally +0 The finally block is unconditionally executed.
                  with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
                  assert +1 The assert statement internally roughly equals a conditional statement.
                  Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
                  Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

                  Source: http://radon.readthedocs.org/en/latest/intro.html

                  Cyclomatic complexity is too high in function module_name_and_doc. (6)
                  Open

                  def module_name_and_doc(relative_path):
                      assert relative_path.startswith(PACKAGE)
                      file, ext = os.path.splitext(relative_path)
                      assert ext == ".py"
                      names = []

                  Cyclomatic Complexity

                  Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

                  Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

                  Construct Effect on CC Reasoning
                  if +1 An if statement is a single decision.
                  elif +1 The elif statement adds another decision.
                  else +0 The else statement does not cause a new decision. The decision is at the if.
                  for +1 There is a decision at the start of the loop.
                  while +1 There is a decision at the while statement.
                  except +1 Each except branch adds a new conditional path of execution.
                  finally +0 The finally block is unconditionally executed.
                  with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
                  assert +1 The assert statement internally roughly equals a conditional statement.
                  Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
                  Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

                  Source: http://radon.readthedocs.org/en/latest/intro.html

                  Severity
                  Category
                  Status
                  Source
                  Language