Sample

pyint-9feae1f7e4c5-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines31

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.850–1; higher is more readable
Mi0.5730–1; higher is more readable
LLOC20Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5640–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 _InValidator: options = attrib() _original_options = attrib(hash=False) def __call__(self, inst, attr, value): try: in_options = value in self.options except TypeError: # e.g. `1 in "abc"` in_options = False if not in_options: msg = f"'{attr.name}' must be in {self._original_options!r} (got {value!r})" raise ValueError( msg, attr, self._original_options, value, ) def __repr__(self): return f"<in_ validator with options {self._original_options!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.737.534−24.339
Source linesThe number of non-empty source lines.31+12.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.373−6.559

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.88+0.615
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.05+0.454
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.30+0.301
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.88−0.062
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.31−0.061
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.30.775+0.02

Intercept 0.07 + feature contributions = 1.735 (log-odds).
Score = sigmoid(1.735) = 0.85.

Score0.573
Score20
Run 1

The code is well-structured with a single class definition containing a clear purpose. Nesting is minimal with one try-except block and an if statement. The intent is obvious: validate that a value belongs to a set of allowed options. The code is concise with no unnecessary verbosity. Action granularity is good—each logical operation is on its own line, like the try block, error message construction, and exception raising. Reading flow is natural: initialize, check membership, handle errors, raise exception if needed. The only minor deduction is the lack of type hints and a docstring, which would clarify the parameter types and the validator's contract for maintainers.

Run 2

The code is generally readable and well-structured. It uses clear naming (_InValidator), flat control flow with minimal nesting, and concise logic. Each action is on its own line, improving clarity. The try/except handles a specific edge case with an explanatory comment, showing clear intent. The class structure is logical, with attributes, call method, and repr grouped appropriately. Docstrings are absent, but the single-purpose design and clear error message make intent understandable. The use of attrs reduces boilerplate, though it may add slight cognitive overhead for readers unfamiliar with it. Overall, it is concise and follows natural reading flow, but lacks a class-level docstring to explicitly document purpose.

Run 3

The code is well-structured and highly readable. It uses clear class and method names, minimal nesting with a single try/except and a flat conditional check, and maintains a concise length. Each logical step is separated into distinct actions: membership testing, error handling, message construction, and raising the exception. The try/except is narrowly scoped and explicitly documents a potential TypeError cause. The `__repr__` is clear and informative. The only minor deduction is the slightly packed single-line `except TypeError:` comment, which could benefit from a separate comment line for enhanced readability, but overall the intent, structure, and flow are excellent.

Run 1

Code Structure: The class is logically organized into attributes, validation, and representation methods, though several imports are unused in this snippet. Nesting: Shallow try/except and conditional blocks are easy to follow. Clarity of intent: Descriptive names and a concrete TypeError example clearly communicate membership validation; the distinction between options and _original_options is not explained. Code length: Concise overall, although the multiline exception construction is slightly verbose. Action granularity: Each line performs a single clear action. Reading flow: Execution proceeds naturally from membership testing to error handling and reporting, with helpful whitespace.

Run 2

Code Structure: The validator is logically organized into attributes, validation, and representation methods, though several unused imports add clutter. Nesting: Shallow try/except and a single conditional keep control flow easy to follow. Clarity of intent: Descriptive names, a helpful TypeError example, and an informative error message clearly communicate membership validation; the distinction between options and _original_options is not explained locally. Code length: The implementation is concise, although the multiline exception construction is somewhat verbose. Action granularity: Each statement performs a single clear action. Reading flow: Validation proceeds naturally from checking membership to handling invalid values, followed by a straightforward representation method.

Run 3

Code Structure: The validator class is logically organized into attributes, validation behavior, and representation, though several imports are unused in this snippet. Nesting: Shallow try/except and conditional blocks make control flow easy to follow. Clarity of intent: Membership validation is explicit, with descriptive names, a helpful TypeError comment, and an informative error message; the distinction between options and _original_options is not explained. Code length: The implementation is concise, although the multiline exception construction is slightly verbose. Action granularity: Each statement performs a single clear action. Reading flow: Execution proceeds naturally from checking membership to handling failure, with whitespace separating logical steps.