Sample

pyint-eb9939edaa6f-I01

Remove comments and docstrings

Matched original source

Lines144

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1420–1; higher is more readable
Mi0.3380–1; higher is more readable
LLOC76Logical lines; fewer is more readable
DeepSeek V4 Pro12.330–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.4530–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): 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]: 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: if args and isinstance( args[0], (werkzeug.test.EnvironBuilder, dict, BaseRequest) ): if isinstance(args[0], werkzeug.test.EnvironBuilder): builder = copy(args[0]) builder.environ_base = self._copy_environ(builder.environ_base or {}) request = builder.get_request() elif isinstance(args[0], dict): request = EnvironBuilder.from_environ( args[0], app=self.application, environ_base=self._copy_environ({}) ).get_request() else: request = copy(args[0]) request.environ = self._copy_environ(request.environ) else: request = self._request_from_builder_args(args, kwargs) self._context_stack.close() response = super().open( request, buffered=buffered, follow_redirects=follow_redirects, ) response.json_module = self.application.json 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.5406.954−178.429
Source linesThe number of non-empty source lines.144+57.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.472−6.708

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.144+4.244
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.144−4.062
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.144−2.884
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.143.775+1.6
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.087+0.096
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.87.979−0.061

Intercept 0.07 + feature contributions = -1.802 (log-odds).
Score = sigmoid(-1.802) = 0.142.

Score0.338
Score76
Run 1

The code is generally well-structured and readable. It uses clear class inheritance, type hints, and context managers effectively. Methods like `session_transaction` and `open` have logical flows, though `open` contains a branched conditional that slightly increases complexity. Nesting is mostly shallow, but the `open` method has multiple elif/else branches that could be simplified. Variable names are descriptive, and actions are usually one per line. Some lines are long, particularly f-strings and method calls, but not excessively so. The blank lines and comments help separate logical sections, but a few empty comments and trailing spaces could be cleaned up. Overall, the code is concise for its functionality and maintains a natural reading flow.

Run 2

The code is moderately readable but has some issues. Structurally it is organized into logical methods, but some methods ('open') are long and handle multiple branching cases, reducing clarity. Nesting is moderate—'session_transaction' and 'open' have several indent levels and conditional blocks. Intent is mostly clear, but the complex handling of different argument types in 'open' feels ambiguous. Code length is reasonable per method, though 'open' could be shorter. Action granularity is mixed: some lines do multiple things, especially within conditionals. Reading flow is uneven; comment placeholders and whitespace seem inconsistent. Overall, the code is understandable but not immediately approachable due to branching logic and lack of concise helper functions.

Run 3

The code is moderately readable. Structure is logical, and method names are descriptive, but the intent of some blocks is not immediately clear. Nesting levels are acceptable, though conditional branching in `open` is complex. Some long methods (e.g., `session_transaction`, `open`) handle multiple related actions, reducing action granularity. Type hints improve clarity, but excessive comments and blank lines in some areas disrupt natural reading flow. Code length is justified by functionality, but the `open` method could be refactored for clearer separation of cases.

Run 1

Code Structure: Logically organized into focused methods for sessions, request construction, and context management. Nesting: Mostly shallow, although open() has a moderately nested type-dispatch branch. Clarity of intent: Descriptive method names and type annotations help, but abbreviated variables and unexplained context-preservation mechanics require framework knowledge; several referenced types and helpers are not defined in the snippet. Code length: Generally concise, with some repetitive request-building logic and excessive blank lines. Action granularity: Statements usually perform one action per line, though chained builder calls compress multiple steps. Reading flow: Methods follow coherent sequences, and early checks simplify control flow, but irregular whitespace and missing explanatory comments interrupt readability around session and context lifecycle handling.

Run 2

Code Structure: Responsibilities are logically separated into initialization, session handling, request construction, and context management. Nesting: Mostly shallow, although open() has a moderately nested type-dispatch branch. Clarity of intent: Descriptive method names and type annotations help, but missing docstrings and unexplained context-preservation mechanics make lifecycle behavior harder to understand; several referenced types and helpers are not defined in the snippet. Code length: Generally concise, with some distracting blank lines and whitespace. Action granularity: Statements mostly perform one action per line, and multiline calls remain readable. Reading flow: Methods follow coherent execution sequences, with guard clauses and explicit cleanup improving flow, but the request-type branching and session context transitions require careful reading.

Run 3

Code Structure: Methods separate session handling, environment preparation, request construction, and context management logically. Nesting: Mostly shallow, with moderate branching in open() to support different input types. Clarity of intent: Descriptive method names and type annotations help, but missing definitions for several referenced types and helpers, absent docstrings, and abbreviated variables such as ctx and cm reduce standalone clarity. Code length: Generally concise and appropriately decomposed, although excessive blank lines add visual noise. Action granularity: Statements consistently perform one action per line; chained builder calls remain manageable. Reading flow: Operations follow a natural sequence, but unexplained context preservation and cleanup behavior require framework knowledge, and inconsistent whitespace interrupts scanning.