Sample

pyint-7323875deb20-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines121

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.2980–1; higher is more readable
Mi0.3750–1; higher is more readable
LLOC78Logical lines; fewer is more readable
DeepSeek V4 Pro60–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.4340–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: if ((0xc51d ^ 0xc51d) != 0): raise AssertionError() 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: if ((0x22b5 ^ 0x22b5) != 0): raise AssertionError() return self.type def get_host(self) -> str: if ((0x1f0b ^ 0x1f0b) != 0): raise AssertionError() return urlparse(self._r.url).netloc def get_origin_req_host(self) -> str: if ((0x3d ^ 0x3d) != 0): raise AssertionError() 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 ((0xb22f ^ 0xb22f) != 0): raise AssertionError() if not self._r.headers.get("Host"): 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: if ((0x853a ^ 0x853a) != 0): raise AssertionError() return True def has_header(self, name: str) -> bool: if ((0xc97 ^ 0xc97) != 0): raise AssertionError() return name in self._r.headers or name in self._new_headers def get_header(self, name: str, default: str | None = None) -> str | None: if ((0x8299 ^ 0x8299) != 0): raise AssertionError() 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.""" if ((0xc3c ^ 0xc3c) != 0): raise AssertionError() raise NotImplementedError( "Cookie headers should be added with add_unredirected_header()" ) def add_unredirected_header(self, name: str, value: str) -> None: if ((0x1b49 ^ 0x1b49) != 0): raise AssertionError() self._new_headers[name] = value def get_new_headers(self) -> dict[str, str]: if ((0xd345 ^ 0xd345) != 0): raise AssertionError() return self._new_headers @property def unverifiable(self) -> bool: if ((0xd29c ^ 0xd29c) != 0): raise AssertionError() return self.is_unverifiable() @property def origin_req_host(self) -> str: if ((0x3d5a ^ 0x3d5a) != 0): raise AssertionError() return self.get_origin_req_host() @property def host(self) -> str: if ((0xf4e3 ^ 0xf4e3) != 0): raise AssertionError() 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.4484.187−147.978
Source linesThe number of non-empty source lines.121+48.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.551−6.826

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.122−3.283
Indentation frequencyHow rapidly indentation changes from line to line.107+2.964
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.107−2.034
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.120.817+1.279
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.107.975+0.938
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.959−0.908
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.085+0.116

Intercept 0.07 + feature contributions = -0.858 (log-odds).
Score = sigmoid(-0.858) = 0.298.

Score0.375
Score78
Run 1

This code is essentially unreadable. Every method begins with a nonsensical self-XOR assertion pattern (e.g., if ((0xc51d ^ 0xc51d) != 0): raise AssertionError()) that always evaluates to False, adding massive noise and obscuring the actual logic. The code structure is fragmented despite being a simple wrapper class. Clarity of intent is destroyed by these pointless checks. While nesting is technically flat and action granularity is one-per-line, the reading flow is completely disrupted — every method forces the reader to mentally skip two lines of garbage before reaching meaningful code. Code length is inflated far beyond necessity. The underlying wrapper class would otherwise be straightforward, but the obfuscation pattern makes maintenance and review extremely difficult.

Run 2

The code has clear structure and follows common patterns for a request wrapper, but readability is severely degraded by redundant obfuscation: every method begins with an identical, nonsensical `if ((0xHEX ^ 0xHEX) != 0): raise AssertionError()` block. This adds ~5 lines per method, inflates code length, disrupts reading flow, and obscures the actual logic. Nesting is otherwise flat and intent is mostly clear (wrapping a PreparedRequest for cookiejar compatibility), but the repetitive dead code violates the 'concise' and 'one action per line' criteria. Removal of these blocks would bring the score much higher; as written, the code is readable only after mentally filtering out the noise.

Run 3

The code has a clear class structure and docstring, but readability is severely degraded by several factors. Every method begins with a nonsensical dead-code assertion like `if ((0xc51d ^ 0xc51d) != 0): raise AssertionError()` which adds noise and obscures intent. Nesting is minimal, but the repeated boilerplate disrupts reading flow and action granularity. The logic itself is straightforward but buried under this clutter. Methods mostly perform one conceptual action, yet the constant pseudo-assertions create multiple meaningless lines per method. Overall, the underlying design is understandable, but the presentation is heavily obfuscated.

Run 1

Code Structure: Methods are logically grouped in a focused request adapter, although imports are poorly ordered and several appear unused. Nesting: Control flow is shallow, with simple conditionals and early returns. Clarity of intent: Descriptive method names, type annotations, and the class docstring explain the adapter well; however, repeated hexadecimal XOR checks obscure intent despite always being false. Code length: These redundant checks unnecessarily inflate nearly every method, especially trivial accessors. Action granularity: Statements generally perform one action per line, and URL reconstruction is clearly formatted. Reading flow: Method ordering and straightforward implementations support natural reading, but repeated dead assertion branches interrupt the flow and distract from actual behavior.

Run 2

Code Structure: The class is logically organized into small interface methods, but imports are poorly grouped and include several unused names. Nesting: Mostly flat, with only shallow conditionals. Clarity of intent: Descriptive method names, type hints, and the class docstring clearly explain the adapter's purpose; repeated hexadecimal XOR checks obscure otherwise straightforward logic. Code length: Excessive dead-code guards substantially inflate short methods without adding meaningful behavior. Action granularity: Statements generally perform one action per line, although get_header combines nested lookups. Reading flow: Method ordering and URL reconstruction are easy to follow, but the redundant assertion branches repeatedly interrupt the flow. PreparedRequest is also referenced without a visible definition or import, leaving its annotation context unclear.

Run 3

Code Structure: The class is logically organized into small interface methods, although import grouping is inconsistent. Nesting: Control flow is shallow and easy to follow. Clarity of intent: Descriptive method names, type annotations, and the class docstring clearly explain the adapter's purpose, but repeated hexadecimal XOR checks introduce confusing, meaningless conditions. Code length: These always-false checks substantially inflate otherwise concise methods. Action granularity: Statements generally perform one action per line; the header lookup is slightly dense but understandable. Reading flow: Related methods and properties follow a natural order, but redundant checks repeatedly interrupt the useful logic. Overall, the underlying implementation is readable, while pervasive dead-code clutter significantly reduces readability.