mike0sv/pyjackson

View on GitHub

Showing 18 of 163 total issues

Function __new__ has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    def __new__(mcs, name, bases, namespace, **kwargs):
        if kwargs.get('__base_definition__', False):
            kwargs.pop('__base_definition__')
            mcs.__root__ = super().__new__(mcs, name, bases, namespace, **kwargs)
            return mcs.__root__
Severity: Minor
Found in src/pyjackson/pydantic_ext.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 _transform_to_class_methods has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

def _transform_to_class_methods(cls):
    metaclass = type(cls)
    mro = inspect.getmro(cls)
    ignore = {'__class__', '__dict__', '__bases__', '__name__', '__qualname__',
              '__mro__', '__subclasses__', '__init_subclass__', '__subclasshook__',
Severity: Minor
Found in src/pyjackson/generics.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 type_field has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

def type_field(field_name, position: Position = Position.INSIDE, allow_reregistration=False):
    """Class decorator for polymorphic hierarchies to define class field name, where subclass's type alias will be stored
    Use it on hierarchy root class, add class field  with defined name to any subclasses
    The same field name will be used during deserialization

Severity: Minor
Found in src/pyjackson/decorators.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 deserialize has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

def deserialize(obj, as_class: SerializerType):
    """Convert python dict into given class

    :param obj: dict (or list or any primitive) to deserialize
    :param as_class: type or serializer
Severity: Minor
Found in src/pyjackson/deserialization.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_string has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def make_string(*fields: str, include_name=True):
    """
    Decorator to create a `__str__` method for class based on `__init__` arguments

    Usage: directly :func:`@make_string` on class declaration to include all fields
Severity: Minor
Found in src/pyjackson/decorators.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 _construct_from_dict has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def _construct_from_dict(obj, as_class):
    kwargs = {}
    for f in get_class_fields(as_class):
        name = f.name
        field_type = _get_field_type(f, obj)
Severity: Minor
Found in src/pyjackson/deserialization.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 serialize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def serialize(obj, as_class: SerializerType = None):
    """
    Convert object into JSON-compatible dict (or other  structure)

    :param obj: object to serialize
Severity: Minor
Found in src/pyjackson/serialization.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 _get_defining_class has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def _get_defining_class(cls, method, method_name=None, mro=None, stop_class=None):
    mro = mro or inspect.getmro(cls)
    method_name = method_name or method.__name__
    for parent in mro:
        m = parent.__dict__.get(method_name)
Severity: Minor
Found in src/pyjackson/generics.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 _serialize_to_dict has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def _serialize_to_dict(cls, obj):
    result = {}
    fields = get_class_fields(cls)
    for f in fields:
        name = f.name
Severity: Minor
Found in src/pyjackson/serialization.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 _construct_from_list has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def _construct_from_list(obj, as_class):
    args = []
    if type_field_position_is(as_class, Position.INSIDE):
        obj = obj[1:]
    for i, f in enumerate(get_class_fields(as_class)):
Severity: Minor
Found in src/pyjackson/deserialization.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 get_type_name_repr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def get_type_name_repr(cls):
    if is_generic(cls):
        typename = getattr(cls, '_name', str(cls.__origin__))
        if typename.startswith('typing.'):
            typename = typename[len('typing.'):]
Severity: Minor
Found in src/pyjackson/_typing_utils.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 _argspec_to_fields has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

def _argspec_to_fields(f, arguments, defaults, hints, types_required=True) -> typing.List[Field]:
Severity: Minor
Found in src/pyjackson/utils.py - About 35 mins to fix

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

    def _get_defining_class(cls, method, method_name=None, mro=None, stop_class=None):
    Severity: Minor
    Found in src/pyjackson/generics.py - About 35 mins to fix

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

      def _construct_object(obj, as_class: Type):
          if isinstance(as_class, Hashable) and as_class in SERIALIZER_MAPPING:
              as_class = SERIALIZER_MAPPING[as_class]
      
          if issubclass(as_class, StaticSerializer):
      Severity: Minor
      Found in src/pyjackson/deserialization.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 _argspec_to_fields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def _argspec_to_fields(f, arguments, defaults, hints, types_required=True) -> typing.List[Field]:
          defaults_num = len(defaults) if defaults is not None else 0
          non_defaults_num = len(arguments) - defaults_num
          fields = []
          for i, arg in enumerate(arguments):
      Severity: Minor
      Found in src/pyjackson/utils.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

      Avoid too many return statements within this function.
      Open

          return _serialize_as_type(obj, as_class)
      Severity: Major
      Found in src/pyjackson/serialization.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return seq_type([deserialize(o, seq_int_type) for o in obj])
        Severity: Major
        Found in src/pyjackson/deserialization.py - About 30 mins to fix

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

              def __new__(cls, **kwargs):
                  has_init = issubclass(_get_defining_class(cls, cls.__init__), Serializer)
                  if getattr(cls, '_dynamic', False):
                      if has_init:
                          cls.__init__(cls, **kwargs)
          Severity: Minor
          Found in src/pyjackson/generics.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