Sample

pyint-1d72ce529dce-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines28

Scores

MethodScoreScale
Posnett0.0010–1; higher is more readable
Dorn0.7770–1; higher is more readable
Mi0.0760–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5380–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, slots=True, unsafe_hash=True) class _InstanceOfValidator: type = attrib() def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if not isinstance(value, self.type): msg = f"'{attr.name}' must be {self.type!r} (got {value!r} that is a {value.__class__!r})." raise TypeError( msg, attr, self.type, value, ) def __repr__(self): return f"<instance_of validator for type {self.type!r}>"

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.635.312−20.965
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.417−6.626

Intercept 8.87 + feature contributions = -7.521 (log-odds).
Score = sigmoid(-7.521) = 0.001.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.103+0.857
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.103−0.697
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.048+0.472
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
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.27.779−0.022
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.25 (log-odds).
Score = sigmoid(1.25) = 0.777.

Score0.076
Score17
Run 1

The code is highly readable with a clear, single-purpose class. It has a flat structure with minimal nesting—only a single conditional inside the __call__ method. The intent is explicit: a validator that checks if a value is an instance of a specified type, raising a descriptive TypeError otherwise. The code is concise, with no unnecessary lines. Action granularity is appropriate; each line performs one logical step, such as constructing the error message or raising the exception. Reading flow is natural, following a top-down progression from imports to class definition and methods. The use of attrs for class definition and f-strings for error messages enhances clarity. Minor deductions only because the type annotation (type = attrib()) could be more explicit, and the error message construction is slightly verbose, but overall it's clean and maintainable.

Run 2

The code demonstrates high readability through clear structure, minimal nesting, and explicit intent. The class is logically organized with a focused single responsibility, and methods are concise with clear names. Nesting is shallow, limited to a single conditional check, and the error message construction is clear. Action granularity is well-balanced: each meaningful operation is on its own line, while simple assignments remain compact. Reading flow is natural from imports through class definition to method implementations. Minor deductions come from the unused imports (operator, re, Pattern, contextmanager, and several attrs-related items), which introduce slight ambiguity about intent. The repr method's one-line return is acceptable given its simplicity. Overall, the code is highly readable and maintainable.

Run 3

The code is highly readable. It has a clear, single-purpose class with a logical structure. Nesting is minimal, with only one conditional inside the __call__ method. Intent is explicit: validating instance types. The code is concise, avoids unnecessary length, and each action is clearly separated, particularly in the __call__ method. The reading flow is natural, with class definitions and methods ordered logically. Imports are grouped and followed by the class definition, enhancing organization. The only minor issue is the slightly long f-string message, but it remains understandable and well-formatted. Overall, this is clean, idiomatic Python.

Run 1

Code Structure: Imports and a focused validator class are logically organized, though several imports are unused in this snippet. Nesting: Shallow nesting makes the validation path easy to follow. Clarity of intent: The class name, isinstance check, descriptive error message, and custom representation clearly communicate purpose; the docstring explains the callable-class design, although abbreviations and library-specific decorators require some familiarity. Code length: Concise overall, with minor visual overhead from the multiline exception construction. Action granularity: Each statement performs a distinct action, cleanly separating message creation from raising the exception. Reading flow: Natural progression from configuration to validation and representation, slightly weakened by the missing blank-line separation before the decorated class.

Run 2

Code Structure: Imports and a small validator class are logically organized, though several imports are unused in this snippet. Nesting: Only a single conditional keeps the code flat and easy to follow. Clarity of intent: The class name, isinstance check, descriptive error message, and custom repr clearly communicate the validator's purpose; the __call__ docstring explains the class design rather than the method's behavior. Code length: The implementation is concise, although the multiline exception construction is somewhat verbose. Action granularity: Each statement performs one clear action, with message creation separated from raising the exception. Reading flow: The progression from configuration to validation to representation is natural, with minor friction from the long error-message line and framework-specific decorators.

Run 3

Code Structure: Imports, class definition, validation method, and representation method are logically organized, though several imports are unused in this snippet. Nesting: A single conditional keeps the code shallow and easy to follow. Clarity of intent: The class name, isinstance check, descriptive error message, and __repr__ clearly communicate type validation; the docstring explains the callable-class design rather than the method's behavior. Code length: The implementation is concise, although the multiline exception construction is somewhat verbose. Action granularity: Each statement performs one clear action, with message construction separated from raising the exception. Reading flow: The code proceeds naturally from configuration to validation and representation, with minor distractions from unused imports and a long error-message line.