Sample

pyint-46f2ccbb0737-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines26

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4110–1; higher is more readable
Mi0.0710–1; higher is more readable
LLOC19Logical lines; fewer is more readable
DeepSeek V4 Pro12.670–20; mean of three runs
GPT-6.1 Sol15.330–20; mean of three runs
BTTF0.6820–1; higher is more readable

Views

Source code

import ipaddress import math import re from pathlib import Path from urllib.parse import urlsplit from django.core.exceptions import ValidationError from django.utils.deconstruct import deconstructible from django.utils.http import MAX_URL_LENGTH from django.utils.ipv6 import is_valid_ipv6_address from django.utils.regex_helper import _lazy_re_compile from django.utils.translation import gettext_lazy as _ from django.utils.translation import ngettext_lazy @deconstructible class MinLengthValidator(BaseValidator): message = ngettext_lazy( "Ensure this value has at least %(limit_value)d character (it has " "%(show_value)d).", "Ensure this value has at least %(limit_value)d characters (it has " "%(show_value)d).", "limit_value", ) code = "min_length" def compare(self, a, b): return a < b def clean(self, x): return len(x)

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.722.67−23.848
Source linesThe number of non-empty source lines.26+10.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.681−7.022

Intercept 8.87 + feature contributions = -11.6 (log-odds).
Score = sigmoid(-11.6) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.104−0.74
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.043+0.523
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Indentation frequencyHow rapidly indentation changes from line to line.26+0.162
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.27+0.08
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.25.857−0.048

Intercept 0.07 + feature contributions = -0.359 (log-odds).
Score = sigmoid(-0.359) = 0.411.

Score0.071
Score19
Run 1

The code has a reasonable structure with logical imports and a clear class definition, but readability suffers from inconsistent formatting. The message string concatenation is awkwardly broken across lines with misaligned indentation, making it harder to follow. The methods compare() and clean() are simple and flat, which is good, but they are placed on adjacent lines without a blank line between them (though inside a class this is acceptable). The multi-line ngettext_lazy call has poor vertical alignment and odd spacing, reducing clarity. The code is concise and the intent is understandable if the reader knows Django validators, but the formatting inconsistencies make it less readable than it could be. Action granularity is generally one action per line, and nesting is minimal. Overall, the logic is straightforward, but the presentation could be significantly improved with better spacing and alignment.

Run 2

The code imports many dependencies but only directly uses a few, creating ambiguity about its actual functionality. The class definition is straightforward, but the multi-line string concatenation in the 'message' attribute is awkward and harms readability. While the class methods are simple and have clear intent, the code lacks logical structure due to unorganized imports and unclear string formatting. Nesting is flat and method length is concise, but the reading flow is disrupted by mixed formatting and unnecessary complexity in the message definition.

Run 3

The code demonstrates moderate readability with some notable issues. Positives include logical imports and a clear class definition that follows Django validator patterns. The class structure is straightforward, and variable names like 'MinLengthValidator' communicate intent well. However, the `message` attribute has awkward line breaks and inconsistent spacing that disrupts visual flow and makes it difficult to parse. The `compare` and `clean` methods are defined on consecutive lines without blank line separation, reducing readability. Method bodies are minimal but lack spacing between class members. The code imports several modules that aren't used in the visible snippet, suggesting unnecessary length. Overall, while the core logic is simple and understandable, formatting inconsistencies and missing structural separations prevent higher readability scores.

Run 1

Code Structure: The validator class is logically organized with message metadata and small methods, but unrelated imports and an undefined BaseValidator reduce self-contained readability. Nesting: Minimal nesting makes the code easy to scan. Clarity of intent: The class name, error message, and straightforward comparisons clearly communicate minimum-length validation, though generic parameter names provide little context. Code length: The implementation is concise, but numerous unused imports add clutter. Action granularity: Each method performs one simple action per line; the message declaration has awkward spacing and adjacent string literals. Reading flow: The class reads naturally from configuration to behavior, but inconsistent formatting and the missing blank line between methods interrupt the flow.

Run 2

Code Structure: The validator is logically organized into class metadata and two small methods, but unrelated imports add clutter and BaseValidator is not imported in the snippet. Nesting: Minimal nesting makes the code easy to follow. Clarity of intent: The class name, validation message, and methods clearly communicate minimum-length validation, although parameter names a, b, and x are generic. Code length: The implementation is concise, but numerous unused imports unnecessarily lengthen the snippet. Action granularity: Each method performs one simple action, with no combined statements. Reading flow: The overall sequence is natural, but inconsistent spacing and awkward string-literal formatting disrupt the message declaration, and missing blank lines between methods reduce visual separation.

Run 3

Code Structure: The validator is logically organized into class attributes and two small methods, but numerous unused imports and an undefined BaseValidator weaken its standalone clarity. Nesting: Minimal nesting makes the code easy to follow. Clarity of intent: The class name, error code, and straightforward comparisons clearly express minimum-length validation, although generic parameter names provide little context. Code length: The implementation is concise, but the unused imports add clutter. Action granularity: Each method performs a single clear action; the message declaration is harder to scan because adjacent string literals and irregular spacing obscure its layout. Reading flow: Imports, metadata, and methods follow a natural order, but inconsistent formatting and missing blank lines between methods interrupt readability.