Sample

pyint-00599e188990-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines27

Scores

MethodScoreScale
Posnett0.0010–1; higher is more readable
Dorn0.8610–1; higher is more readable
Mi0.3590–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro150–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.7040–1; higher is more readable

Views

Source code

from __future__ import annotations import collections.abc as c import hashlib import typing as t from collections.abc import MutableMapping from datetime import datetime from datetime import timezone from itsdangerous import BadSignature from itsdangerous import URLSafeTimedSerializer from werkzeug.datastructures import CallbackDict from .json.tag import TaggedJSONSerializer class NullSession(SecureCookieSession): """Class used to generate nicer error messages if sessions are not available. Will still allow read-only access to the empty session but fail on setting. """ def _fail(self, *args: t.Any, **kwargs: t.Any) -> t.NoReturn: raise RuntimeError( "The session is unavailable because no secret " "key was set. Set the secret_key on the " "application to something unique and secret." ) __setitem__ = __delitem__ = clear = pop = popitem = update = setdefault = _fail del _fail

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.615.58−20.314
Source linesThe number of non-empty source lines.27+10.8
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.527−6.791

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

Feature contributions

FeatureValueContribution
(log-odds)
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.034+0.614
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.80.071+0.487
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
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.82.893+0.154
Indentation frequencyHow rapidly indentation changes from line to line.24+0.093
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.28+0.045
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.26.857−0.034

Intercept 0.07 + feature contributions = 1.827 (log-odds).
Score = sigmoid(1.827) = 0.861.

Score0.359
Score17
Run 1

The code is highly readable, with clear imports, a single purpose, and a clean class definition. The NullSession class is logically structured, and the _fail method clearly communicates intent with a descriptive error message. Nesting is minimal, and each assignment of methods to _fail is concise. Action granularity is well handled, as the method aliasing is compact but still understandable. The only minor drawback is the slight ambiguity in the import of collections.abc as c, which is unused, but this does not significantly impact readability.

Run 2

The code is moderately readable. It has clear intent with a dedicated NullSession class and a helpful error message. The structure is logical, and the class is concise. However, readability is reduced by the assignment of multiple methods to a single helper in one line, compressing several actions and making the class API harder to scan. The import section is slightly cluttered with unused or redundant imports (`collections.abc as c`, `hashlib`, `datetime`, `itsdangerous` items, `CallbackDict`, `TaggedJSONSerializer`), which obscures the actual dependencies. The use of `t.NoReturn` and `t.Any` is clear, but the overall flow feels fragmented due to import noise. Nesting is minimal, and action granularity is mostly good except for the method aliasing line. Overall, it is understandable but could be improved by cleaning imports and expanding the aliased methods for clarity.

Run 3

The code is generally well-structured but has some readability issues. The class structure is clear, and the NullSession class serves a specific purpose with a clear error message. The _fail method is concise and readable. However, the line assigning multiple methods to _fail is dense and may be difficult to follow for those unfamiliar with Python's ability to chain assignments. The imports are mostly clear, but using 'import collections.abc as c' and 'import typing as t' adds aliases that may not be immediately obvious to all readers. The code length is appropriate for its purpose, and the reading flow is mostly natural. The main drawback is the chained assignment, which sacrifices one-action-per-line clarity for brevity.

Run 1

Code Structure: The class is logically organized around one failure handler, though several imports are unused and the base class is not defined or imported in the snippet. Nesting: Minimal nesting makes the code easy to scan. Clarity of intent: The class docstring and explicit error message clearly explain why session mutations fail; the chained method assignment requires some Python familiarity. Code length: The implementation is concise, but unused imports add clutter. Action granularity: Most lines perform a single action, while assigning seven methods in one statement reduces immediate readability. Reading flow: The progression from documentation to error handler to method overrides is natural, although deleting the helper afterward is a less obvious implementation detail.

Run 2

Code Structure: The class is logically organized around a documented purpose, although many imports are unused in this snippet and SecureCookieSession is not defined or imported. Nesting: Minimal nesting makes the code easy to scan. Clarity of intent: The docstring and descriptive exception clearly explain why session mutations fail. Code length: The implementation is concise, with one shared failure method avoiding repetition. Action granularity: Most lines express a single action, but the chained assignment binds seven mutation methods at once, making it denser than the surrounding code. Reading flow: The progression from documentation to failure behavior to method bindings is natural, though the chained assignment and deletion of _fail require some familiarity with Python class construction.

Run 3

Code Structure: The class is logically organized, with a descriptive docstring and a shared failure handler, although several imports are unused in this snippet and the base class is not shown. Nesting: Minimal nesting makes the code easy to scan. Clarity of intent: The class name, docstring, and explicit error message clearly explain its purpose; the chained method assignments require familiarity with Python special methods. Code length: The implementation is concise without repetitive method definitions. Action granularity: Most lines perform one action, but assigning seven methods on one line reduces immediate readability. Reading flow: The progression from documentation to error handler to mutation-method overrides is natural, though deleting the helper afterward is slightly surprising.