Sample

pyint-d65a8a93dd81-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines25

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8390–1; higher is more readable
Mi0.3180–1; higher is more readable
LLOC19Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.560–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 _NumberValidator: bound = attrib() compare_op = attrib() compare_func = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not self.compare_func(value, self.bound): msg = f"'{attr.name}' must be {self.compare_op} {self.bound}: {value}" raise ValueError(msg) def __repr__(self): return f"<Validator for x {self.compare_op} {self.bound}>"

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.655.551−21.633
Source linesThe number of non-empty source lines.25+10
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.578−6.867

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.78.731+0.466
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.055+0.41
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
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.81.923+0.195
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.26+0.116
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.24.771−0.064
Indentation frequencyHow rapidly indentation changes from line to line.23+0.058

Intercept 0.07 + feature contributions = 1.65 (log-odds).
Score = sigmoid(1.65) = 0.839.

Score0.318
Score19
Run 1

The code is well-structured with clear imports, proper use of frozen attrs, and a single-purpose validator class. Nesting is minimal, and each method has a clear intent. The __call__ method handles validation concisely with a clear error message, while __repr__ provides useful debugging info. However, readability could improve with a type hint for 'inst' (likely unused), a more descriptive docstring, and slightly more context around the class purpose. The mix of validation logic and repr in one small class is acceptable but could be separated for clarity. Overall, it's readable and maintainable with only minor improvements needed.

Run 2

The code is well-structured and readable. It uses a frozen, slotted attrs class with clear attribute declarations. The class has a single responsibility: numeric comparison validation. Nesting is minimal, with only one conditional inside __call__. Intent is clear from class and method names, and the docstring explains the design choice. The error message is informative. Code length is concise and avoids unnecessary verbosity. Each logical action is separated: import block, class definition, attribute declarations, validation logic, and repr. The only minor drawback is that __call__ combines the condition check and error raising in two lines, which is acceptable but could be slightly more explicit. Overall, the reading flow is natural and the code is easy to follow.

Run 3

The code is generally clear and well-structured. The validator class is logically organized with a simple __call__ method that checks a condition and raises a ValueError with a descriptive message. Nesting is minimal, with only one if statement inside __call__. The use of type hints and attrs decorators demonstrates clear intent. The __repr__ method is concise and gives a useful summary of the validator. However, the code imports several items (operator, re, Pattern, etc.) that are not used within this snippet, which adds unnecessary noise. The compare_op and compare_func attributes could be confusing without context about how they're instantiated. The code is concise for what it does, but the unused imports slightly reduce clarity. Overall, this is readable code with minor improvements possible.

Run 1

Code Structure: The validator class cleanly separates stored configuration, validation behavior, and representation; several unused imports add clutter. Nesting: A single conditional keeps control flow shallow. Clarity of intent: Descriptive names and the error message make the numeric-bound check clear, although the docstring explains the callable-class design rather than the validation behavior. Code length: The implementation is concise, with little unnecessary code beyond the unused imports. Action granularity: Each statement performs one clear action, and constructing the error message separately improves readability. Reading flow: Configuration followed by validation and representation is natural; an additional blank line before the class would improve visual separation.

Run 2

Code Structure: The validator is logically organized into attributes, validation behavior, and representation, though several unused imports add clutter. Nesting: Minimal nesting makes the control flow easy to follow. Clarity of intent: Descriptive names and the error message clearly communicate numeric-bound validation; the docstring explains the callable-class design rather than the method's behavior. Code length: The class is concise, but the unused imports unnecessarily lengthen the snippet. Action granularity: Each statement performs one clear action, with message construction separated from raising the exception. Reading flow: Attributes followed by __call__ and __repr__ provide a natural progression; slightly more spacing around the import groups and class declaration would improve presentation.

Run 3

Code Structure: Imports and a focused validator class are logically organized, though several imports are unused in this snippet. Nesting: The code is shallow, with only one conditional inside a method. Clarity of intent: Descriptive field names, a straightforward validation check, and informative error and representation strings make the purpose clear; the docstring explains the callable-class design rather than the validation behavior. Code length: The implementation is concise without unnecessary logic. Action granularity: Each statement performs one clear action, and message construction is separated from raising the exception. Reading flow: Fields, validation behavior, and representation follow a natural order, though additional spacing between imports and the class would improve visual separation.