Sample

pyint-9d2c35dd3bd5-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines53

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.7260–1; higher is more readable
Mi0.390–1; higher is more readable
LLOC37Logical lines; fewer is more readable
DeepSeek V4 Pro11.670–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.5850–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 not (exc_val is not None): pass else: self.errors.append(exc_val) return True def raise_any(self, message: str) -> None: """Raise if any errors were collected.""" if not (self.errors): pass else: 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.1439.146−47.492
Source linesThe number of non-empty source lines.53+21.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.463−6.695

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.50+0.992
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.54−0.876
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.50−0.727
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.055+0.412
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.963+0.405
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.72.741+0.369
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.52.846+0.329

Intercept 0.07 + feature contributions = 0.975 (log-odds).
Score = sigmoid(0.975) = 0.726.

Score0.39
Score37
Run 1

The code has good structure with clear section separation and adequate type hints, but several readability issues drag the score down. The conditional logic in `__exit__` and `raise_any` uses awkward 'if not condition: pass else:' patterns instead of direct positive conditions, making the intent less clear than it should be. The imports are somewhat disorganized—stdlib and third-party imports are mixed together without clear grouping. The `raise_any` method has unnecessary branching complexity with version-specific handling that could be more clearly commented or extracted. The code is concise and avoids deep nesting, which is positive, but the redundant `pass` statements and inverted conditionals add noise. The action granularity is mostly good with one action per line. Overall, the code is functional but could be significantly more readable with cleaner conditionals and better import organization.

Run 2

The code has a clear purpose and decent structure with a single class and clear documentation. However, several issues reduce readability: conditional statements use awkward `if not (condition): pass else:` patterns that could be simplified to `if condition:`; nested conditionals in `raise_any` add unnecessary depth; the `__enter__` method is empty but not marked as a no-op clearly; multiple imports and the unused `BaseResponse` import suggest incomplete organization. The `__exit__` method's logic is straightforward but written in an inverted, harder-to-read style. Line length and action granularity are generally acceptable, but the overall clarity suffers from these stylistic choices. The code could be significantly more readable with direct conditional statements, removal of unused imports, and flattening nested logic.

Run 3

The code has clear intent with reasonable docstrings and type hints, but the structure and flow are significantly hampered by convoluted conditional patterns. The `if not (condition): pass else: ...` construct in both `__exit__` and `raise_any` is unnecessarily verbose and inverts natural reading flow—a simple early return would be far clearer. The `raise_any` method also contains a version-conditional `# noqa: F821` for `BaseExceptionGroup` which obscures intent and creates potential runtime fragility. Imports are organized but somewhat excessive for the small amount of logic present. The `__exit__` method's parameter list and empty `__enter__` are boilerplate-heavy. While the class purpose is understandable, the implementation choices reduce overall readability, making it harder to scan quickly. Nesting is minimal, which is positive, and the code is concise overall, but these advantages are undermined by awkward conditionals and implicit behavior.

Run 1

Code Structure: The context manager is logically organized into initialization, entry, exit, and error reporting, but many imports are unused in this snippet. Nesting: Depth is modest, although inverted conditions with empty pass branches introduce unnecessary else blocks and nesting. Clarity of intent: The class docstring, method names, and type annotations clearly explain error collection and deferred raising; awkward conditional phrasing slightly obscures simple checks. Code length: The implementation is short, but redundant branches and unrelated imports make it longer than necessary. Action granularity: Each statement performs one clear action, with no compressed multi-action lines. Reading flow: Methods follow the context-manager lifecycle naturally, but expressions such as 'if not (exc_val is not None)' interrupt straightforward reading. Direct positive checks would substantially improve readability.

Run 2

Code Structure: The context-manager class is logically organized into initialization, entry, exit, and error propagation, but numerous unused imports distract from its purpose. Nesting: Depth is modest, although redundant if/pass/else branches add unnecessary nesting. Clarity of intent: The class docstring, method names, and type annotations clearly explain error collection and delayed raising; negated conditions make simple checks harder to interpret. Code length: The implementation is short overall, but unused imports and empty branches unnecessarily expand it. Action granularity: Each line generally performs one action, making individual operations easy to follow. Reading flow: Methods follow a natural lifecycle, but double-negative-style checks and avoidable else blocks interrupt otherwise straightforward control flow.

Run 3

Code Structure: The context-manager class is logically organized into initialization, entry, exit, and error reporting, but many unused imports clutter the snippet. Nesting: Nesting is modest, though inverted conditions with empty pass branches introduce unnecessary else blocks, especially in raise_any. Clarity of intent: The class docstring, descriptive method names, and type annotations clearly explain error collection and deferred raising. However, expressions such as 'if not (exc_val is not None)' are harder to parse than direct checks. Code length: The implementation is short, but redundant branches and imports make it longer than necessary. Action granularity: Each line generally performs one action, making individual operations easy to follow. Reading flow: Method ordering is natural and the version-dependent exception handling is understandable, but repeated pass/else patterns interrupt an otherwise straightforward flow.