ionelmc/python-fields

View on GitHub

Showing 17 of 17 total issues

File __init__.py has 372 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
How it works: the library is composed of 2 major parts:

* The `sealers`. They return a class that implements a container according the given specification (list of field names
  and default values).
Severity: Minor
Found in src/fields/__init__.py - About 4 hrs to fix

    Function class_sealer has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

    def class_sealer(fields, defaults,
                     base=__base__, make_init_func=make_init_func,
                     initializer=True, comparable=True, printable=True, convertible=False, pass_kwargs=False):
        """
        This sealer makes a normal container class. It's mutable and supports arguments with default values.
    Severity: Minor
    Found in src/fields/__init__.py - About 4 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 make_init_func has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def make_init_func(fields, defaults,
                       baseclass_name='FieldsBase',
                       header_name='__init__',
                       header_start='def {func_name}(self',
                       header_end='):\n',
    Severity: Minor
    Found in src/fields/__init__.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 __new__ has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def __new__(mcs, name="__blank__", bases=(), namespace=None, last_field=None, required=(), defaults=(),
                    sealer=_SealerWrapper(class_sealer)):
    
            if not bases:
                assert isinstance(sealer, _SealerWrapper)
    Severity: Minor
    Found in src/fields/__init__.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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        def __iter__(self):
            end = self.__end
            curr = end[2]
            while curr is not end:
                yield curr[0]
    Severity: Major
    Found in src/fields/py2ordereddict.py and 1 other location - About 2 hrs to fix
    src/fields/py2ordereddict.py on lines 63..68

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 56.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        def __reversed__(self):
            end = self.__end
            curr = end[1]
            while curr is not end:
                yield curr[0]
    Severity: Major
    Found in src/fields/py2ordereddict.py and 1 other location - About 2 hrs to fix
    src/fields/py2ordereddict.py on lines 56..61

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 56.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    def regex_validation_sealer(fields, defaults, RegexType=type(re.compile(""))):
        """
        Example sealer that just does regex-based validation.
        """
        required = set(fields) - set(defaults)
    Severity: Minor
    Found in src/fields/extras.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 make_init_func has 12 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def make_init_func(fields, defaults,
    Severity: Major
    Found in src/fields/__init__.py - About 1 hr to fix

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

      def class_sealer(fields, defaults,
      Severity: Major
      Found in src/fields/__init__.py - About 1 hr to fix

        Function exec_in_env has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def exec_in_env():
            env_path = join(base_path, ".tox", "bootstrap")
            if sys.platform == "win32":
                bin_path = join(env_path, "Scripts")
            else:
        Severity: Minor
        Found in ci/bootstrap.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 __new__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __new__(mcs, name="__blank__", bases=(), namespace=None, last_field=None, required=(), defaults=(),
        Severity: Major
        Found in src/fields/__init__.py - About 50 mins to fix

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

              def __eq__(self, other):
                  if isinstance(other, OrderedDict):
                      if len(self) != len(other):
                          return False
                      for p, q in zip(self.items(), other.items()):
          Severity: Minor
          Found in src/fields/py2ordereddict.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_latest_artifacts has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def download_latest_artifacts(account_project, build_id):
              """Download all the artifacts from the latest build."""
              if build_id is None:
                  url = "https://ci.appveyor.com/api/projects/{}".format(account_project)
              else:
          Severity: Minor
          Found in ci/appveyor-download.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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  for pos, (value, validator) in enumerate(zip(args, arg_validators)):
                      if not validator.match(value):
                          raise ValidationError("Positional argument %s failed validation. %r doesn't match regex %r" % (
                              pos, value, validator.pattern
          Severity: Minor
          Found in src/fields/extras.py and 1 other location - About 35 mins to fix
          src/fields/extras.py on lines 38..40

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 33.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                          if not validator.match(value):
                              raise ValidationError("Keyword argument %r failed validation. %r doesn't match regex %r" % (
                                  key, value, validator.pattern
          Severity: Minor
          Found in src/fields/extras.py and 1 other location - About 35 mins to fix
          src/fields/extras.py on lines 30..33

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 33.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

              def __getattr__(cls, name):
                  if name.startswith("__") and name.endswith("__"):
                      return type.__getattribute__(cls, name)
                  if name in cls.__required:
                      raise TypeError("Field %r is already specified as required." % name)
          Severity: Minor
          Found in src/fields/__init__.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 __invert__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def __invert__(cls):
                  if cls.__concrete is None:
                      if not cls.__all_fields:
                          raise TypeError("You're trying to use an empty Fields factory !")
                      if cls.__defaults and cls.__last_field is not None:
          Severity: Minor
          Found in src/fields/__init__.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