Sample

pyint-a982da214d28-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines41

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8730–1; higher is more readable
Mi0.5590–1; higher is more readable
LLOC24Logical lines; fewer is more readable
DeepSeek V4 Pro5.670–20; mean of three runs
GPT-6.1 Sol130–20; mean of three runs
BTTF0.5930–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 _DeepIterable: member_validator = attrib(validator=is_callable()) iterable_validator = attrib( default=None, validator=optional(is_callable()) ) def __call__(self, inst, attr, value): """ We use a callable class to be able to change the ``__repr__``. """ if self.iterable_validator is not None: self.iterable_validator(inst, attr, value) loopIterator = __import__("builtins").iter(value) while True: try: member = __import__("builtins").next(loopIterator) except __import__("builtins").StopIteration: break self.member_validator(inst, attr, member) def __repr__(self): iterable_identifier = ( "" if self.iterable_validator is None else f" {self.iterable_validator!r}" ) return ( f"<deep_iterable validator for{iterable_identifier}" f" iterables of {self.member_validator!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.1136.186−37.494
Source linesThe number of non-empty source lines.41+16.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.334−6.501

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

Feature contributions

FeatureValueContribution
(log-odds)
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.69.976+0.701
Indentation frequencyHow rapidly indentation changes from line to line.39+0.612
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.42−0.451
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.059+0.371
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.40.761+0.16
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.53.738+0.063

Intercept 0.07 + feature contributions = 1.924 (log-odds).
Score = sigmoid(1.924) = 0.873.

Score0.559
Score24
Run 1

The code has a clear class structure and purpose, but readability is significantly hindered by the use of `__import__('builtins')` instead of direct built-in functions (`iter`, `next`) or a for loop. This makes the iteration logic unnecessarily verbose and difficult to follow. The `while True` loop with manual exception handling for `StopIteration` adds nesting and complexity that could be replaced by a simple `for member in value:` loop. The `__call__` method lacks clear separation of concerns, mixing validation logic with control flow. While the code is concise and follows consistent formatting, the unusual built-in access pattern obscures intent. The `__repr__` method is readable and well-structured. Overall, the code would be much more readable with idiomatic Python iteration and fewer workarounds.

Run 2

The code scores very low on readability. Structure is unclear due to odd dynamic imports: repeatedly calling __import__('builtins') instead of using Python's built-in 'iter' and 'next' directly, which obscures intent and breaks natural flow. Nesting is acceptable but the while-try-except pattern creates awkward control flow. Clarity of intent is hampered by the unnecessary dynamic imports, confusing naming ('loopIterator' is not Pythonic), and a misleading comment about changing __repr__ that doesn't explain why it matters. Action granularity is poor: multiple operations are crammed into lines like 'except __import__('builtins').StopIteration:'. Code length is acceptable overall. Reading flow feels disjointed and artificial. The class could be far more readable with direct built-in calls, a for-loop using 'iter()', and simplified names.

Run 3

The code suffers from multiple readability issues. The dynamic import using `__import__("builtins")` is highly unusual and obscures intent; direct use of `iter`, `next`, and `StopIteration` would be clearer. The `while True` loop with a `try/except` for control flow is less Pythonic than a `for` loop. The class structure is reasonable with `attrs`, but the `__call__` method mixes validation logic with iteration in a way that adds nesting. Naming is inconsistent (`loopIterator` uses camelCase against Python convention). The `__repr__` method is compact but uses a conditional expression that reduces clarity. Action granularity is mostly one-per-line, but the dynamic import calls are overloaded. Overall the code has a logical class structure, but the implementation details and non-idiomatic constructs significantly hurt readability.

Run 1

Code Structure: The class logically groups configuration, validation, and representation, though several unused imports add clutter. Nesting: Mostly shallow, with moderate nesting in the while/try/except iteration. Clarity of intent: Validator names clearly convey their roles, but dynamic builtins imports obscure ordinary iteration, and is_callable and optional are not defined or imported in the snippet. Code length: Reasonably short overall, but a simple for loop would replace the unnecessarily verbose iterator handling. Action granularity: Statements generally perform one action per line, although repeated dynamic imports complicate otherwise simple operations. Reading flow: Validation proceeds naturally from the iterable to its members, and representation is separated cleanly; however, the unconventional loopIterator name, repetitive imports, and implementation-focused docstring interrupt readability.

Run 2

Code Structure: The class logically groups validator attributes, validation behavior, and representation, though unused imports add clutter. Nesting: Mostly shallow, but the while/try/except iteration introduces unnecessary nesting compared with a for loop. Clarity of intent: Validator names clearly express their purpose; repeated dynamic builtins imports and the inconsistent loopIterator naming distract from that intent. The docstring explains the callable-class choice rather than validation behavior, and is_callable and optional are not defined or imported in the excerpt. Code length: Reasonably compact overall, but manual iterator handling unnecessarily expands a simple operation. Action granularity: Statements generally perform one action per line, with readable multiline expressions. Reading flow: Attributes and methods follow a natural order, but low-level iteration mechanics interrupt the otherwise straightforward validation flow.

Run 3

Code Structure: The class logically separates configuration, validation, and representation, although several imports appear unused in this snippet. Nesting: Mostly shallow, with a modestly nested while/try/except loop. Clarity of intent: Validator names communicate purpose, but loopIterator breaks naming conventions, and repeated dynamic builtins imports obscure ordinary iteration. The docstring explains the callable-class design rather than the method's validation behavior. Code length: Reasonably compact overall, but manual iterator management is unnecessarily verbose compared with a for loop. Action granularity: Statements generally perform one action per line, though dynamic imports embedded in iteration operations add complexity. Reading flow: Validation proceeds naturally from the iterable to its members, and representation is isolated appropriately; however, the unusual iteration machinery interrupts that flow.