stxnext/mappet

View on GitHub

Showing 12 of 12 total issues

File mappet.py has 528 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-

u"""Module for dynamic mapping of XML trees to Python objects.

.. :module: mappet
Severity: Major
Found in mappet/mappet.py - About 1 day to fix

    Function dict_to_etree has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

    def dict_to_etree(d, root):
        u"""Converts a dict to lxml.etree object.
    
        >>> dict_to_etree({'root': {'#text': 'node_text', '@attr': 'val'}}, etree.Element('root')) # doctest: +ELLIPSIS
        <Element root at 0x...>
    Severity: Minor
    Found in mappet/helpers.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

    Mappet has 31 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Mappet(Node):
        u"""A node that may have children."""
    
        _aliases = None
        u"""Dictionary with node aliases.
    Severity: Minor
    Found in mappet/mappet.py - About 3 hrs to fix

      Function etree_to_dict has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

      def etree_to_dict(t, trim=True, **kw):
          u"""Converts an lxml.etree object to Python dict.
      
          >>> etree_to_dict(etree.Element('root'))
          {'root': None}
      Severity: Minor
      Found in mappet/helpers.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 sget has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def sget(self, path, default=NONE_NODE):
              u"""Enables access to nodes if one or more of them don't exist.
      
              Example:
              >>> m = Mappet('<root><tag attr1="attr text">text value</tag></root>')
      Severity: Minor
      Found in mappet/mappet.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 xpath has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def xpath(
                  self,
                  path,
                  namespaces=None,
                  regexp=False,
      Severity: Minor
      Found in mappet/mappet.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 e is None:
                                  if child_num == 0:
                                      # Found the first occurrence of an empty child,
                                      # skip creating of its XML repr, since it would be
                                      # the same as ``sub_element`` higher up.
      Severity: Major
      Found in mappet/helpers.py - About 45 mins to fix

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

            def xpath(
        Severity: Minor
        Found in mappet/mappet.py - About 35 mins to fix

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

              def update(self, **kwargs):
                  u"""Updating or creation of new simple nodes.
          
                  Each dict key is used as a tagname and value as text.
                  """
          Severity: Minor
          Found in mappet/mappet.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 iter_children has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def iter_children(self, key=None):
                  u"""Iterates over children.
          
                  :param key: A key for filtering children by tagname.
                  """
          Severity: Minor
          Found in mappet/mappet.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 __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def __init__(self, xml):
                  u"""Creates the mappet object from either lxml object, a string or a dict.
          
                  If you pass a dict without root element, one will be created for you with
                  'root' as tag name.
          Severity: Minor
          Found in mappet/mappet.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 _get_aliases has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def _get_aliases(self):
                  u"""Creates a dict with aliases.
          
                  The key is a normalized tagname, value the original tagname.
                  """
          Severity: Minor
          Found in mappet/mappet.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