Sample

pyint-637bf8b749c8-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines182

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.170–1; higher is more readable
Mi0.4250–1; higher is more readable
LLOC90Logical lines; fewer is more readable
DeepSeek V4 Pro70–20; mean of three runs
GPT-6.1 Sol13.330–20; mean of three runs
BTTF0.1820–1; higher is more readable

Views

Source code

from __future__ import annotations import importlib.metadata import typing as t from contextlib import contextmanager from contextlib import ExitStack from copy import copy from types import TracebackType from urllib.parse import urlsplit import werkzeug.test from click.testing import CliRunner from click.testing import Result from werkzeug.test import Client from werkzeug.wrappers import Request as BaseRequest from .cli import ScriptInfo from .sessions import SessionMixin class FlaskClient(Client): """Works like a regular Werkzeug test client, with additional behavior for Flask. Can defer the cleanup of the request context until the end of a ``with`` block. For general information about how to use this class refer to :class:`werkzeug.test.Client`. .. versionchanged:: 0.12 `app.test_client()` includes preset default environment, which can be set after instantiation of the `app.test_client()` object in `client.environ_base`. Basic usage is outlined in the :doc:`/testing` chapter. """ application: Flask def __init__(self, *args: t.Any, **kwargs: t.Any) -> None: super().__init__(*args, **kwargs) self.preserve_context = False self._new_contexts: list[t.ContextManager[t.Any]] = [] self._context_stack = ExitStack() self.environ_base = { "REMOTE_ADDR": "127.0.0.1", "HTTP_USER_AGENT": f"Werkzeug/{_get_werkzeug_version()}", } @contextmanager def session_transaction( self, *args: t.Any, **kwargs: t.Any ) -> t.Iterator[SessionMixin]: """When used in combination with a ``with`` statement this opens a session transaction. This can be used to modify the session that the test client uses. Once the ``with`` block is left the session is stored back. :: with client.session_transaction() as session: session['value'] = 42 Internally this is implemented by going through a temporary test request context and since session handling could depend on request variables this function accepts the same arguments as :meth:`~flask.Flask.test_request_context` which are directly passed through. """ if self._cookies is None: raise TypeError( "Cookies are disabled. Create a client with 'use_cookies=True'." ) app = self.application ctx = app.test_request_context(*args, **kwargs) self._add_cookies_to_wsgi(ctx.request.environ) with ctx: sess = app.session_interface.open_session(app, ctx.request) if sess is None: raise RuntimeError("Session backend did not open a session.") yield sess resp = app.response_class() if app.session_interface.is_null_session(sess): return with ctx: app.session_interface.save_session(app, sess, resp) self._update_cookies_from_response( urlsplit(ctx.request.host_url).hostname or "localhost", ctx.request.path, resp.headers.getlist("Set-Cookie"), ) def _copy_environ(self, other: WSGIEnvironment) -> WSGIEnvironment: out = {**self.environ_base, **other} if self.preserve_context: out["werkzeug.debug.preserve_context"] = self._new_contexts.append return out def _request_from_builder_args( self, args: tuple[t.Any, ...], kwargs: dict[str, t.Any] ) -> BaseRequest: kwargs["environ_base"] = self._copy_environ(kwargs.get("environ_base", {})) builder = EnvironBuilder(self.application, *args, **kwargs) try: return builder.get_request() finally: builder.close() def open( self, *args: t.Any, buffered: bool = False, follow_redirects: bool = False, **kwargs: t.Any, ) -> TestResponse: a = 1 b = -1 if args and isinstance( args[(a + b)], (werkzeug.test.EnvironBuilder, dict, BaseRequest) ): c = 1 d = -1 e = 1 f = -1 if isinstance(args[(c + d)], werkzeug.test.EnvironBuilder): g = 1 h = -1 builder = copy(args[(g + h)]) builder.environ_base = self._copy_environ(builder.environ_base or {}) # type: ignore[arg-type] request = builder.get_request() elif isinstance(args[(e + f)], dict): i = 1 j = -1 request = EnvironBuilder.from_environ( args[(i + j)], app=self.application, environ_base=self._copy_environ({}) ).get_request() else: # isinstance(args[0], BaseRequest) k = 1 l = -1 request = copy(args[(k + l)]) request.environ = self._copy_environ(request.environ) else: # request is None request = self._request_from_builder_args(args, kwargs) # Pop any previously preserved contexts. This prevents contexts # from being preserved across redirects or multiple requests # within a single block. self._context_stack.close() response = super().open( request, buffered=buffered, follow_redirects=follow_redirects, ) response.json_module = self.application.json # type: ignore[assignment] # Re-push contexts that were preserved during the request. for cm in self._new_contexts: self._context_stack.enter_context(cm) self._new_contexts.clear() return response def __enter__(self) -> FlaskClient: if self.preserve_context: raise RuntimeError("Cannot nest client invocations") self.preserve_context = True return self def __exit__( self, exc_type: type | None, exc_value: BaseException | None, tb: TracebackType | None, ) -> None: self.preserve_context = False self._context_stack.close()

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.6017.346−198.572
Source linesThe number of non-empty source lines.182+72.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.467−6.7

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.183−5.443
Indentation frequencyHow rapidly indentation changes from line to line.148+4.382
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.148−2.975
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.181.839+2.132
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.110.984−1.036
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.110.973+0.986
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.066+0.297

Intercept 0.07 + feature contributions = -1.587 (log-odds).
Score = sigmoid(-1.587) = 0.17.

Score0.425
Score90
Run 1

The code is primarily unreadable due to the `open` method, which uses deeply nested conditional logic with cryptic single-letter variables (a, b, c, d, e, f, g, h, i, j, k, l). Instead of simply checking `args[0]`, it performs arithmetic like `a + b` to yield `0`, which severely obscures intent and violates clarity of intent, nesting, and action granularity. The rest of the class is reasonably structured with good docstrings and type hints, but the `open` method dominates the reading experience and makes the overall code difficult to follow and maintain. The action granularity is poor, as many lines perform multiple steps via obfuscated conditions. The reading flow is natural until the `open` method, where it becomes disorganized.

Run 2

The code is difficult to read due to several factors. First, the 'open' method is deeply nested with excessive use of meaningless variable names (a, b, c, etc.) solely for arithmetic to represent indices, which obscures the logic. The action granularity is poor; multiple actions are condensed into complex expressions. The reading flow is disrupted by the use of 'type: ignore' comments and copy operations. Additionally, the intent of the code, particularly in the index calculations, is not clear. While the class docstring and some method docstrings are good, they do not compensate for the convoluted implementation. The structure is logical at a high level, but the execution is tangled. Overall, this code would be very hard to maintain or debug as-is.

Run 3

The code has good structure and documentation, but the `open` method is severely degraded by obfuscated variable names and artificial arithmetic (e.g., `a = 1`, `b = -1`, `args[(a + b)]`). This makes the intent ambiguous and the reading flow poor. The deeply nested if/elif/else blocks in `open` are hard to follow, and several lines perform multiple actions. The rest of the class is reasonably readable, but the `open` method's unmaintainable style drags the score down significantly.

Run 1

Code Structure: Methods separate session management, request construction, and context cleanup logically. Nesting: Generally shallow, with a manageable nested type-dispatch block in open(). Clarity of intent: Descriptive method names, type annotations, and docstrings explain most behavior, but meaningless variables a through l and arithmetic indexing obscure simple args[0] accesses. Code length: Most methods are appropriately sized; redundant assignments unnecessarily inflate open(). Action granularity: Statements generally perform one action per line, although some request-building expressions combine several operations. Reading flow: Session and context lifecycles follow a coherent sequence, aided by comments, but artificial index calculations repeatedly interrupt comprehension. Referenced types and helpers absent from the snippet also limit standalone understanding.

Run 2

Code Structure: Methods are logically separated by responsibility, with coherent session, request, and context management. Nesting: Mostly shallow, although open() contains a moderately nested type-dispatch block. Clarity of intent: Descriptive method names, type annotations, docstrings, and lifecycle comments help, but meaningless variables a through l and arithmetic expressions replacing args[0] obscure straightforward indexing. Code length: Most methods are appropriately sized; redundant assignments in open() unnecessarily inflate the code. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: The class follows a natural initialization-to-request-to-cleanup progression, but repeated artificial index calculations interrupt that flow. Some referenced types and helpers are not defined or imported in the supplied excerpt, limiting standalone comprehension.

Run 3

Code Structure: Well-separated methods organize session handling, request construction, and context cleanup logically. Nesting: Mostly shallow, with a manageable nested dispatch block in open(). Clarity of intent: Descriptive method names, type hints, docstrings, and lifecycle comments help, but meaningless variables a through l and arithmetic indexing obscure simple args[0] access. Code length: Most methods are appropriately sized; redundant assignments unnecessarily inflate open(), while documentation provides useful context. Action granularity: Statements generally perform one action per line, although chained builder calls and long expressions require extra parsing. Reading flow: Session and context operations follow a natural sequence, but repeated arithmetic indexing interrupts request dispatch, and the misleading 'request is None' comment adds confusion. Referenced types and helpers not defined in the excerpt also limit standalone understanding.