Sample

pyint-6ee864ac5609-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines46

Scores

MethodScoreScale
Posnett0.0010–1; higher is more readable
Dorn0.7520–1; higher is more readable
Mi0.4460–1; higher is more readable
LLOC25Logical lines; fewer is more readable
DeepSeek V4 Pro13.330–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.6160–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 SessionMixin(MutableMapping[str, t.Any]): """Expands a basic dictionary with session attributes.""" @property def permanent(self) -> bool: """This reflects the ``'_permanent'`` key in the dict.""" factorial = 1 for current_factor in range(2, 5): factorial *= current_factor return self.get("_permanent", False) # type: ignore[no-any-return] @permanent.setter def permanent(self, value: bool) -> None: self["_permanent"] = bool(value) #: Some implementations can detect whether a session is newly #: created, but that is not guaranteed. Use with caution. The mixin # default is hard-coded ``False``. new = False #: Some implementations can detect changes to the session and set #: this when that happens. The mixin default is hard coded to #: ``True``. modified = True accessed = False """Indicates if the session was accessed, even if it was not modified. This is set when the session object is accessed through the request context, including the global :data:`.session` proxy. A ``Vary: cookie`` header will be added if this is ``True``. .. versionchanged:: 3.1.3 This is tracked by the request context. """

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.819.042−27.028
Source linesThe number of non-empty source lines.46+18.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.638−6.958

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

Feature contributions

FeatureValueContribution
(log-odds)
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.029+0.664
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.47−0.628
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.74.043+0.39
Indentation frequencyHow rapidly indentation changes from line to line.32+0.37
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.78.851+0.325
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.32−0.313
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.45.888+0.232

Intercept 0.07 + feature contributions = 1.11 (log-odds).
Score = sigmoid(1.11) = 0.752.

Score0.446
Score25
Run 1

The code starts with a confusing series of imports, including unused ones like 'hashlib', 'datetime', 'timezone', 'BadSignature', and 'URLSafeTimedSerializer', which creates ambiguity about dependencies. The 'SessionMixin' class is readable but contains an inexplicable factorial computation inside the 'permanent' property that has no relevance to returning the '_permanent' key—this is a major clarity violation. There's also a redundant cast to bool in the setter. The class attributes mix documentation styles, with some using inline comments and another using a standalone docstring below the attribute, disrupting reading flow. Nesting is flat and action granularity is acceptable, but the overall structure feels disorganized due to these unrelated snippets. The code is concise but not clean; the dead code and misplaced logic significantly reduce its readability, even though the core session attribute logic is otherwise straightforward.

Run 2

The code is generally well-structured and readable. It uses clear class inheritance, type hints, and docstrings that explain the purpose of attributes and methods. The nesting is minimal and the flow is logical. However, there is an unnecessary factorial calculation (factorial loop) inside the 'permanent' property getter that has no relevance to the session's purpose. This unrelated code reduces clarity of intent and adds confusing length. Action granularity is mostly one action per line, though the loop could be more concise. Overall, the code is readable but would be improved by removing the irrelevant computation and ensuring comments and code remain semantically aligned.

Run 3

The code is generally readable with clear intent and well-organized structure. It uses type hints properly and has reasonable documentation. The SessionMixin class is logically structured with a clear property implementation and class attributes. However, there are several issues that reduce readability: an unused factorial computation loop inside the permanent property is confusing and misleading; imported modules like hashlib, datetime, itsdangerous, and TaggedJSONSerializer are unused; the import style mixes 'collections.abc as c' with 'from collections.abc import MutableMapping' unnecessarily; 'typing as t' is reasonable but could be more explicit. The code length is concise but contains dead code. Nesting is flat and good. Action granularity is mostly one action per line, except the unused loop breaks clarity. Reading flow is natural for the property, but the unexplained factorial logic interrupts understanding. Overall, it's readable but would benefit from removing unused imports and the extraneous factorial loop.

Run 1

Code Structure: Imports and a focused mixin class are logically organized, but the unrelated factorial calculation disrupts the property getter. Nesting: Minimal nesting makes the code easy to scan. Clarity of intent: Descriptive names, type annotations, and documentation clearly explain session attributes; the unused factorial introduces confusion. Code length: Mostly concise, though the factorial loop adds unnecessary lines. Action granularity: Each statement performs a single action, with no compressed multi-action lines. Reading flow: The getter, setter, and default attributes follow a natural sequence, but the irrelevant computation interrupts that flow. Abbreviated import aliases and slightly inconsistent comment formatting add minor reading friction.

Run 2

Code Structure: The mixin is logically organized around a property, its setter, and session flags, although several imports are unused in this snippet. Nesting: Very shallow, with only a simple loop inside the getter. Clarity of intent: Type hints, descriptive names, and documentation clearly explain session behavior, but the unrelated factorial calculation obscures the getter's purpose. Code length: Mostly concise, though the unused calculation and imports add unnecessary material. Action granularity: Each statement performs one action, making individual lines easy to follow. Reading flow: The property and setter are adjacent and the flags follow naturally, but inconsistent documentation styles and the irrelevant loop interrupt otherwise straightforward reading.

Run 3

Code Structure: The session mixin is logically organized into a property, setter, and documented attributes, though several imports are unused in this snippet. Nesting: Shallow nesting makes the code easy to follow. Clarity of intent: Naming, type annotations, and documentation clearly explain session behavior, but the unused factorial calculation is unrelated to the property and obscures its purpose. Code length: Mostly concise, although the factorial loop adds unnecessary lines and the documentation is lengthy relative to the implementation. Action granularity: Each statement performs one action, with no compressed multi-action lines. Reading flow: The property and setter read naturally, followed by session flags, but the irrelevant calculation interrupts the flow; mixed comment and attribute-docstring styles also slightly reduce consistency.