Sample

pyint-def6fe16c343-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines95

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3910–1; higher is more readable
Mi0.3770–1; higher is more readable
LLOC51Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.5580–1; higher is more readable

Views

Source code

from __future__ import annotations import calendar import copy import time from collections.abc import Iterator, MutableMapping from http.cookiejar import Cookie, CookieJar, CookiePolicy from typing import TYPE_CHECKING, Any, TypeVar, overload from ._internal_utils import to_native_string from ._types import is_prepared as _is_prepared from .compat import Morsel, cookielib, urlparse, urlunparse import threading class MockRequest: """Wraps a `requests.PreparedRequest` to mimic a `urllib2.Request`. The code in `http.cookiejar.CookieJar` expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie. The original request object is read-only. The client is responsible for collecting the new headers via `get_new_headers()` and interpreting them appropriately. You probably want `get_cookie_header`, defined below. """ type: str def __init__(self, request: PreparedRequest) -> None: assert _is_prepared(request) self._r = request self._new_headers: dict[str, str] = {} self.type = urlparse(self._r.url).scheme def get_type(self) -> str: return self.type def get_host(self) -> str: return urlparse(self._r.url).netloc def get_origin_req_host(self) -> str: return self.get_host() def get_full_url(self) -> str: # Only return the response's URL if the user hadn't set the Host # header if not (not self._r.headers.get("Host")): pass else: return self._r.url # If they did set it, retrieve it and reconstruct the expected domain host = to_native_string(self._r.headers["Host"], encoding="utf-8") parsed = urlparse(self._r.url) # Reconstruct the URL as we expect it return urlunparse( [ parsed.scheme, host, parsed.path, parsed.params, parsed.query, parsed.fragment, ] ) def is_unverifiable(self) -> bool: return True def has_header(self, name: str) -> bool: return name in self._r.headers or name in self._new_headers def get_header(self, name: str, default: str | None = None) -> str | None: return self._r.headers.get(name, self._new_headers.get(name, default)) # type: ignore[return-value] def add_header(self, key: str, val: str) -> None: """cookiejar has no legitimate use for this method; add it back if you find one.""" raise NotImplementedError( "Cookie headers should be added with add_unredirected_header()" ) def add_unredirected_header(self, name: str, value: str) -> None: self._new_headers[name] = value def get_new_headers(self) -> dict[str, str]: return self._new_headers @property def unverifiable(self) -> bool: return self.is_unverifiable() @property def origin_req_host(self) -> str: return self.get_origin_req_host() @property def host(self) -> str: return self.get_host()

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.2980.469−98.355
Source linesThe number of non-empty source lines.95+38
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.486−6.729

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.96−2.363
Indentation frequencyHow rapidly indentation changes from line to line.81+2.065
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.81−1.438
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.106.927+0.921
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.94.817+0.916
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.107.958−0.907
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.067+0.296

Intercept 0.07 + feature contributions = -0.442 (log-odds).
Score = sigmoid(-0.442) = 0.391.

Score0.377
Score51
Run 1

The code is generally well-structured and readable, with clear class and method purposes. Import organization is logical, and type hints improve intent clarity. Each method performs a single action, contributing to good action granularity. The `get_full_url` method contains an awkward and confusing double-negative condition (`if not (not self._r.headers.get("Host"))`) with an empty `pass` block, which significantly hampers clarity. Additionally, the comment inside `get_full_url` slightly disrupts natural reading flow. While nesting is minimal and the code is concise, that one method's logic is unnecessarily convoluted, affecting overall readability. The class is easy to follow otherwise.

Run 2

The code structure is mostly logical, with clear separation of methods and a coherent class purpose, but it is tangled at points. The `get_full_url` method contains an unnecessarily confusing `if not (not ...)` condition with a `pass` branch, which obscures intent and hurts readability. Nesting is mostly flat, which is good, but that one conditional adds avoidable complexity. Clarity of intent is partly undermined by comments that are either misleading or incomplete (e.g., the comment in `get_full_url` is hard to follow). Code length is moderate and not overly verbose. Action granularity is mostly one action per line, though some lines combine multiple operations (e.g., reading and writing headers in `get_header`). Reading flow is generally natural, but the awkward conditional and redundant property methods `unverifiable`, `origin_req_host`, and `host` create unnecessary noise. Overall, it is readable but would benefit from simplifying conditionals and removing redundant wrappers.

Run 3

The code is generally readable but has some confusing parts. It has a clear class structure with logical method separation, but the get_full_url() method contains an inverted, confusing conditional (`if not (not self._r.headers.get("Host")): pass else: return`), which creates avoidable nesting and obscures intent. The empty if branch with a pass is a significant clarity issue. There are minor type hint inconsistencies (e.g., PreparedRequest is not imported or defined). The docstring is helpful, and most methods are concise and single-purpose. Some methods feel redundant or unnecessary, such as forwarding properties. Overall, the organization is good, but the conditional logic and incomplete typing reduce readability.

Run 1

Code Structure: The class is logically organized into small interface methods, although imports are inconsistently grouped and include unused names. Nesting: Generally flat, with only a shallow conditional. Clarity of intent: The class docstring, descriptive method names, and type annotations clearly explain the adapter’s purpose. However, the double negation and empty pass branch in get_full_url obscure a simple condition, and its comment incorrectly refers to a response. Code length: Mostly concise, but the conditional adds unnecessary lines; some thin wrappers are justified by the required interface. Action granularity: Statements generally perform one action per line, and the URL reconstruction is formatted clearly. Reading flow: Mostly natural and easy to scan, interrupted chiefly by the awkward conditional, misplaced threading import, and long get_header line.

Run 2

Code Structure: A cohesive adapter class with logically separated methods, although import ordering is inconsistent and several imports appear unused. Nesting: Mostly flat and easy to follow; get_full_url adds an unnecessary if/pass/else branch. Clarity of intent: The class docstring, descriptive method names, and type annotations explain the purpose well. However, the double negation in the Host check obscures a simple condition, and PreparedRequest is not defined or imported in the snippet. Code length: Generally concise, but redundant control flow and some repetitive comments add avoidable length. Action granularity: Statements consistently perform one action per line, with readable formatting for URL reconstruction. Reading flow: Methods progress naturally from request metadata to header handling and convenience properties; the awkward Host conditional and misplaced threading import interrupt otherwise smooth reading.

Run 3

Code Structure: The class is logically organized around adapting a request to a cookie-handling interface, although unused imports and the misplaced threading import add clutter. Nesting: Methods are mostly flat, with minimal branching. Clarity of intent: Descriptive method names, type annotations, and a detailed class docstring explain the purpose well; however, the double-negative condition and empty pass branch in get_full_url obscure a straightforward Host-header check. Code length: Most methods are concise, but redundant branching, unused imports, and some obvious comments unnecessarily expand the code. Action granularity: Statements generally perform one action per line; the nested dictionary lookup in get_header is compact but slightly harder to scan. Reading flow: Related methods and properties follow a natural sequence, though import ordering, the awkward conditional, and the unexplained PreparedRequest annotation interrupt otherwise clear reading.