Sample

pyint-0ed36ca4a214-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines28

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.750–1; higher is more readable
Mi0.2620–1; higher is more readable
LLOC22Logical lines; fewer is more readable
DeepSeek V4 Pro8.330–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.3870–1; higher is more readable

Views

Source code

import operator import re from contextlib import contextmanager from re import Pattern from ._config import get_run_validators, set_run_validators from ._make import _AndValidator, and_, attrib, attrs from .converters import default_if_none from .exceptions import NotCallableError @attrs(repr=False, frozen=True, slots=True) class _MaxLengthValidator: max_length = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ starting_position = 2 ending_position = 9 travel_distance = ending_position - starting_position if travel_distance < 0: travel_distance = -travel_distance if len(value) > self.max_length: msg = f"Length of '{attr.name}' must be <= {self.max_length}: {len(value)}" raise ValueError(msg) def __repr__(self): return f"<max_len validator for {self.max_length}>"

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.717.682−23.684
Source linesThe number of non-empty source lines.28+11.2
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.541−6.811

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.931+0.598
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.048+0.477
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.26−0.176
Indentation frequencyHow rapidly indentation changes from line to line.26+0.162
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.27.795−0.021
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.87−0.02
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.29+0.01

Intercept 0.07 + feature contributions = 1.1 (log-odds).
Score = sigmoid(1.1) = 0.75.

Score0.262
Score22
Run 1

The code has moderate readability but is dragged down by significant issues. The structure is mostly logical with a single validator class, but the method includes dead code (starting_position, ending_position, travel_distance) that computes nothing relevant to the actual validation logic. This violates clarity of intent and code length. Nesting is flat, which is good, but the unrelated arithmetic adds confusion. Action granularity is mostly one action per line, but the dead lines break flow. Reading flow is somewhat natural aside from the irrelevant block. The class decorators and docstring are clear, and the core validation logic is simple and easy to understand. Removing the unused arithmetic and clarifying the error message would raise the score several points.

Run 2

The code is poorly readable. The core issue is the completely unrelated and nonsensical travel_distance calculation inside _MaxLengthValidator.__call__, which serves no purpose and obscures the actual validation logic. Imports include unused modules (operator, re, Pattern, contextmanager, get_run_validators, set_run_validators, _AndValidator, and_, default_if_none, NotCallableError), adding noise. Structure is weak: a simple length check is padded with irrelevant code, and the nested conditionals are trivial but the surrounding dead code makes the intent unclear. Action granularity is acceptable per line, but the reading flow is disrupted by the meaningless arithmetic. Code length is inflated due to dead imports and unexplained variables. The class-based validator approach is fine, but the implementation here is tangled and ambiguous.

Run 3

The code is generally structured but contains confusing elements that hinder readability. The `_MaxLengthValidator` class uses `@attrs` decorators consistently, and the validator's purpose is clear from its name. However, the `__call__` method includes an unnecessary and misleading distance calculation (starting_position, ending_position, travel_distance) that has no relation to validation logic. This dead code obscures intent. The method does follow one action per line mostly, but the irrelevant arithmetic breaks the reading flow. Nesting is minimal, which is good. A minor improvement would be extracting the error message construction, but the main issue is the unexplained dead code. The import of `contextmanager` and other symbols not used in the snippet also adds minor noise. Overall, the core validator is simple, but the inclusion of pointless logic significantly reduces clarity.

Run 1

Code Structure: The callable validator class logically groups configuration, validation, and representation, but several unused imports add clutter. Nesting: Shallow conditionals keep the code easy to follow. Clarity of intent: Class and attribute names clearly convey maximum-length validation, although the unrelated travel-distance calculation distracts from that purpose and the docstring explains implementation rather than behavior. Code length: The validator is short overall, but unused arithmetic and imports make it unnecessarily long. Action granularity: Each line generally performs one action, with validation and error construction cleanly separated. Reading flow: The class progresses naturally from configuration to validation to representation, but irrelevant calculations interrupt the central validation logic.

Run 2

Code Structure: The validator is logically organized into a class with validation and representation methods, but unrelated calculations and unused imports add clutter. Nesting: Shallow conditionals make the code easy to follow. Clarity of intent: Class and attribute names, the length check, and the error message clearly convey maximum-length validation; however, the unused travel-distance calculation is distracting, and the call-method docstring explains representation rather than validation. Code length: The snippet is short, but several imports and five calculation lines are unnecessary. Action granularity: Each line generally performs one action, improving readability. Reading flow: The flow from configuration to validation to representation is natural, but irrelevant arithmetic interrupts the central validation logic.

Run 3

Code Structure: The validator is logically organized into an attribute, validation method, and representation method, but numerous unused imports add clutter. Nesting: Shallow conditionals make the code easy to scan. Clarity of intent: Class and attribute names clearly communicate maximum-length validation, but the unrelated position and distance calculations obscure that purpose; the docstring explains the callable-class design rather than the method's behavior. Code length: The core validation is concise, but unused calculations and imports unnecessarily lengthen the snippet. Action granularity: Each statement performs one action, with message construction separated from raising the exception. Reading flow: The class follows a natural layout, but irrelevant calculations interrupt the path from receiving a value to checking its length.