File text.py
has 392 lines of code (exceeds 250 allowed). Consider refactoring. Open
import gzip
import re
import secrets
import unicodedata
from collections import deque
Function wrap
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def wrap(text, width):
"""
A word-wrap function that preserves existing line breaks. Expects that
existing line breaks are posix newlines.
- 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 _text_chars
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _text_chars(self, length, truncate, text):
"""Truncate a string after a certain number of chars."""
truncate_len = calculate_truncate_chars_length(length, truncate)
s_len = 0
end_index = None
- 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 __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, *, length, replacement, convert_charrefs=True):
Function calculate_truncate_chars_length
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def calculate_truncate_chars_length(length, replacement):
truncate_len = length
for char in add_truncation_text("", replacement):
if not unicodedata.combining(char):
truncate_len -= 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"