Showing 16 of 16 total issues
Function __restore_dict
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
def __restore_dict(cls, dct, attr_call_list, exclude_type):
ret = cls()
for (name, value) in dct.items():
fld = cls._fields.get(name)
if fld:
- Read upRead up
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
File model.py
has 310 lines of code (exceeds 250 allowed). Consider refactoring. Open
#!/usr/bin/env python
# coding=utf-8
"""Model Base."""
Function __delete_attr
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def __delete_attr(self, target, target_route):
try:
obj = reduce(self.__lookup, target_route[:-1], target)
parent_obj = reduce(self.__lookup, target_route[:-2], target)
(name, index) = self.__split_name_index(target_route[-1])
- Read upRead up
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 __set__
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def __set__(self, obj, value):
"""Set descriptor."""
attrs = self.target.split(self.sep_char)
self.validate()
asdict = getattr(obj, "asdict", False)
- Read upRead up
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
File fields.py
has 271 lines of code (exceeds 250 allowed). Consider refactoring. Open
#!/usr/bin/env python
# coding=utf-8
"""Fields."""
Function __allocate_array
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def __allocate_array(self, asdict, target, attr, current_position,
indexes, value=None):
point = target[attr] if isinstance(target, dict) \
else getattr(target, attr)
for (num, index) in enumerate(indexes):
- Read upRead up
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 __compose_dict
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def __compose_dict(self, priority_list, exclude_type):
dct = {}
for (name, fld) in self.fields.items():
if self.__extend_exclusion(fld, exclude_type, "serialize"):
continue
- Read upRead up
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 _cast_type
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def _cast_type(self, index, default=__NotSpecifiedYet__, index_only=False):
ret = None
try:
ret = self.set_cast[index]
except TypeError as e:
- Read upRead up
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 __validate_consistency
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def __validate_consistency(self, fields=None):
"""Check consistency of the class."""
fields = [
field for field in fields or self.fields.items()
if isinstance(getattr(field[1], "set_cast", None), list)
- Read upRead up
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 __allocate_array
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def __allocate_array(self, asdict, target, attr, current_position,
Function reduce_with_index
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def reduce_with_index(fn, iterable, start=None, *args, **kwargs):
Function check_consistency_for_each_value
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def check_consistency_for_each_value(cur, attr, index,
Similar blocks of code found in 2 locations. Consider refactoring. Open
if current_type is not attr_set_cast:
error_fields.append((name, field))
self._register_error(name, err)
- Read upRead up
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 32.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if current_type is not root_set_cast:
error_fields.append((name, field))
self._register_error(name, err)
- Read upRead up
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 32.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function __correct_value
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def __correct_value(self, target, indexes, value):
result_value = value
if hasattr(self, "set_cast"):
cast = self._cast_type(-1, None)
if not any([cast is None, type(result_value) is cast]):
- Read upRead up
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 __extend_exclusion
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def __extend_exclusion(fld, exclude_type, ser_type):
exclude = getattr(fld, "exclude", None)
exclude_method = getattr(fld, ("exclude_{}").format(ser_type), None)
if any([
- Read upRead up
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"