thesadru/apimodel

View on GitHub
apimodel/parser.py

Summary

Maintainability
C
7 hrs
Test Coverage
A
94%

Function get_validator has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

def get_validator(tp: object, *, model: typing.Optional[type] = None) -> AnnotationValidator:
    """Get a validator for the given type."""
    # TODO: pydantic and dataclasses
    if isinstance(tp, typing.TypeVar):
        tp = resolve_typevar(tp, model=model)
Severity: Minor
Found in apimodel/parser.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 collection_validator has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def collection_validator(
    collection_type: typing.Callable[[typing.Collection[typing.Any]], typing.Collection[object]],
    inner_validator: validation.Validator,
) -> AnnotationValidator:
    """Validate the items of a collection."""
Severity: Minor
Found in apimodel/parser.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 debuggable_deco has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def debuggable_deco(func: tutils.CallableT) -> tutils.CallableT:
    """Make a higher order function's return debuggable."""

    def wrapper(*args: object, **kwargs: object) -> object:
        obj = func(*args, **kwargs)
Severity: Minor
Found in apimodel/parser.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 tuple_validator has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def tuple_validator(tup: typing.Type[typing.Tuple[object, ...]]) -> AnnotationValidator:
    """Validate a namedtuple."""
    if hasattr(tup, "_fields"):
        name = tup.__name__
        types = getattr(tup, "_field_types", {}) or getattr(tup, "__annotations__", {})
Severity: Minor
Found in apimodel/parser.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 resolve_typevar has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def resolve_typevar(tp: typing.TypeVar, *, model: typing.Optional[type] = None) -> object:
    if model is not None:
        typevars = utility.resolve_typevars(model)
        if tp.__name__ not in typevars:
            raise TypeError(f"Undeclared typevar used: {tp}")
Severity: Minor
Found in apimodel/parser.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 union_validator has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

def union_validator(*validators: validation.Validator) -> AnnotationValidator:
    """Return the first successful validator."""
    if len(validators) == 1:
        validator = validators[0]
        if isinstance(validator, AnnotationValidator):
Severity: Minor
Found in apimodel/parser.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

There are no issues that match your filters.

Category
Status