Sample

pyint-2960a8520040-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines49

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7410–1; higher is more readable
Mi0.3840–1; higher is more readable
LLOC35Logical lines; fewer is more readable
DeepSeek V4 Pro180–20; mean of three runs
GPT-6.1 Sol17.670–20; mean of three runs
BTTF0.6210–1; higher is more readable

Views

Source code

from __future__ import annotations import importlib.util import os import sys import typing as t from datetime import datetime from functools import cache from functools import update_wrapper from types import TracebackType import werkzeug.utils from werkzeug.exceptions import abort as _wz_abort from werkzeug.utils import redirect as _wz_redirect from werkzeug.wrappers import Response as BaseResponse from .globals import _cv_app from .globals import app_ctx from .globals import current_app from .globals import request from .globals import session from .signals import message_flashed class _CollectErrors: """A context manager that records and silences an error raised within it. Used to run all teardown functions, then raise any errors afterward. """ def __init__(self) -> None: self.errors: list[BaseException] = [] def __enter__(self) -> None: pass def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None, ) -> bool: if exc_val is not None: self.errors.append(exc_val) return True def raise_any(self, message: str) -> None: """Raise if any errors were collected.""" if self.errors: if sys.version_info >= (3, 11): raise BaseExceptionGroup(message, self.errors) # noqa: F821 else: raise self.errors[0]

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.1363.068−44.981
Source linesThe number of non-empty source lines.49+19.6
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.517−6.776

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.46+0.854
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.50−0.734
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.46−0.635
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.427
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.76.94+0.406
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.73.88+0.388
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.48.846+0.273

Intercept 0.07 + feature contributions = 1.049 (log-odds).
Score = sigmoid(1.049) = 0.741.

Score0.384
Score35
Run 1

The code is highly readable. It has a clear, single-purpose class with a docstring explaining its role. Imports are logically grouped from stdlib to third-party to local. Nesting is minimal, with only one conditional block in raise_any and a version check inside it. Intent is explicit through descriptive names like _CollectErrors, raise_any, and message_flashed. The code is concise without being terse, and each significant action (appending an error, raising) sits on its own line. Reading flow is natural, following a standard class structure: init, enter, exit, helper method. Type hints are used consistently. The only minor deduction is that the `__enter__` method is a no-op with `pass`, which adds a tiny bit of boilerplate, but it is required for context manager protocol and clearly intentional.

Run 2

The code is highly readable. It has a clear single-purpose class with a well-written docstring explaining its role. Imports are organized logically, with future imports first, standard library, third-party, and local modules grouped sequentially. The class methods are concise, each performing one clear action. Nesting is shallow—only one level in raise_any and __exit__. Type hints improve clarity. The only minor deductions are for slightly verbose imports and the conditional BaseExceptionGroup logic, which could be extracted, but overall the structure and intent are excellent.

Run 3

The code is generally clean and readable. The imports are organized, though slightly verbose. The class has a single clear purpose with a concise docstring. Methods are short and focused, with proper type hints. Nesting is minimal, limited to version checks. The __exit__ method clearly collects errors and silences them. The raise_any method is straightforward, though the exception group handling adds minor complexity. Overall, the structure is logical, the flow is natural, and the intent is explicit.

Run 1

Code Structure: The context manager cleanly separates initialization, context entry, error collection, and deferred raising, although many imports are unused in this snippet. Nesting: Most code is flat; raise_any has only two conditional levels. Clarity of intent: Descriptive names, type annotations, and docstrings clearly explain error collection and suppression. Code length: The implementation is concise, but the extensive import block adds clutter relative to the small class. Action granularity: Each statement performs a single action, and the multiline signature remains easy to scan. Reading flow: Methods follow the natural context-manager lifecycle, ending with error propagation. Minor spacing improvements around imports and the class would improve visual organization.

Run 2

Code Structure: The context manager is logically organized into initialization, entry, exit, and deferred error reporting, though many imports are unused in this snippet. Nesting: Most code is flat; raise_any has only modest nested conditionals. Clarity of intent: Descriptive names, type annotations, and docstrings clearly explain error collection and suppression. The unconditional True return is consistent with that purpose. Code length: The implementation is concise, but the extensive import block adds clutter relative to the small class. Action granularity: Each line generally performs one action, making behavior easy to follow. Reading flow: Methods follow the natural context-manager lifecycle, then expose error reporting. Limited spacing between import groups and the class slightly weakens visual organization.

Run 3

Code Structure: The context manager is logically organized into initialization, entry, exit, and error reporting, though many unrelated imports distract from the small class. Nesting: Control flow is shallow, with only two levels in raise_any. Clarity of intent: Descriptive names, type annotations, and docstrings clearly explain error collection and deferred raising; returning True requires familiarity with context-manager exception suppression. Code length: The implementation is concise, but unused imports add unnecessary length to this excerpt. Action granularity: Each line performs a single clear action. Reading flow: Methods follow the natural context-manager lifecycle, then provide error reporting. The Python-version branch is straightforward, although the compatibility annotation and BaseExceptionGroup introduce minor reading overhead.