Sample

pyint-6d64bac5ba98-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines23

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8310–1; higher is more readable
Mi0.260–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6170–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__``. """ 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.578.587−19.093
Source linesThe number of non-empty source lines.23+9.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.609−6.914

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.917+0.598
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.05+0.46
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.24+0.187
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.22.784−0.091
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.86.958−0.018
Indentation frequencyHow rapidly indentation changes from line to line.21−0.011

Intercept 0.07 + feature contributions = 1.592 (log-odds).
Score = sigmoid(1.592) = 0.831.

Score0.26
Score17
Run 1

The code is well-structured and highly readable. It imports only what is needed, defines a single focused class with a clear purpose, and keeps nesting minimal (one level inside __call__). The validation logic is straightforward: check length, raise error with a clear message. The custom __repr__ method enhances debugging. Naming is descriptive, and the docstring clarifies the design choice. The class is concise without unnecessary verbosity, and each logical action is separated naturally. Minor deductions: some imports like operator, re, and Pattern appear unused, and the overall module lacks context, but within the given snippet, readability is strong.

Run 2

The code is well-structured and highly readable. It uses a clear class-based validator with a focused single responsibility. Nesting is minimal, with only one conditional inside the __call__ method. The intent is clear from the class name and docstring, and the action granularity is appropriate — attribute assignment, length check, message construction, and exception raising are separated logically. Reading flow is natural, from imports to class definition to method logic. The use of attrs decorators keeps the code concise. Minor deductions: the __repr__ uses f-string unnecessarily and could be a plain string, and the validation logic is slightly compacted in one block, but these are trivial. Overall, it is clean, maintainable, and easy to understand.

Run 3

The code is highly readable. It follows a clear logical structure with a single-purpose class, flat nesting, and concise length. The intent of validating max length is immediately clear from the class name and docstring. Each action is separated into distinct lines. The reading flow is natural—imports are grouped, the class is self-contained, and helper methods like __call__ and __repr__ are standard and easy to follow. Minor deductions could come from the slightly abbreviated variable name 'attr' and the unused imports at the top, but overall the code is clean and understandable.

Run 1

Code Structure: The validator is logically organized into configuration, validation, and representation methods, although several imports are unused in this snippet. Nesting: A single conditional keeps the implementation flat and easy to follow. Clarity of intent: The class name, max_length attribute, and descriptive error message clearly communicate the purpose; abbreviated parameters and a docstring focused on implementation rationale slightly reduce clarity. Code length: The class is concise, with little unnecessary code beyond the unused imports. Action granularity: Each statement performs one clear action, separating message construction from raising the exception. Reading flow: Execution proceeds naturally from checking length to reporting failure, followed by a straightforward representation method.

Run 2

Code Structure: The class cleanly separates configuration, validation, and representation, though several imports are unused in this snippet. Nesting: A single conditional keeps nesting minimal. Clarity of intent: Descriptive class and attribute names, a straightforward length check, and an informative error message make the purpose clear; the docstring explains the callable-class design rather than the validation behavior. Code length: The implementation is concise, with minor clutter from unused imports and a repeated len(value) call. Action granularity: Each statement performs one clear action. Reading flow: Configuration leads naturally into validation and then representation, although additional spacing between imports and the class would improve visual separation.

Run 3

Code Structure: The validator is logically organized into configuration, validation, and representation methods, though many imports are unused in this snippet. Nesting: A single conditional keeps nesting shallow. Clarity of intent: Class and attribute names clearly communicate maximum-length validation, and the error message is informative; the __call__ docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise without unnecessary logic. Action granularity: Each statement performs one clear action, with message construction separated from raising the exception. Reading flow: The progression from max_length to validation and representation is natural, although the unused imports add distraction.