Sample

pyint-14e07ea0e65a-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines93

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3990–1; higher is more readable
Mi0.4030–1; higher is more readable
LLOC49Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol17.330–20; mean of three runs
BTTF0.5840–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 self._r.headers.get("Host"): return self._r.url # If they did set it, retrieve it and reconstruct the expected domain parsed = urlparse(self._r.url) # Reconstruct the URL as we expect it return urlunparse( [ parsed.scheme, (to_native_string(self._r.headers["Host"], encoding="utf-8")), 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.2921.392−96.406
Source linesThe number of non-empty source lines.93+37.2
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.5−6.75

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.94−2.292
Indentation frequencyHow rapidly indentation changes from line to line.79+1.995
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.79−1.392
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.107.989+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.947−0.907
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.92.817+0.888
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.067+0.291

Intercept 0.07 + feature contributions = -0.409 (log-odds).
Score = sigmoid(-0.409) = 0.399.

Score0.403
Score49
Run 1

The code is highly readable with clear structure and consistent style. The class has a single, well-documented purpose. Methods are short and focused, each performing one action. Nesting is minimal (only one if-block in get_full_url). Type hints are used throughout, enhancing clarity. The docstring explains the class's role and its relationship to cookiejar's expected interface. Method names are descriptive and follow Python conventions. The only minor issues are the # type: ignore comment in get_header and the absence of a docstring on that method, but these are negligible. The code flows naturally from constructor to properties, making it easy to follow.

Run 2

The code is well-structured and readable. It has a clear class purpose, follows consistent naming conventions, and uses docstrings effectively. Each method has a single responsibility, and action granularity is appropriate, with one main operation per line. Nesting is minimal, and the overall flow is logical—request wrapping methods are grouped and easy to follow. The only slight deduction comes from a few verbose type annotations and minor redundancy in property/method pairs, but these do not significantly hinder readability.

Run 3

The code is generally clear and well-structured, with a single class wrapping a PreparedRequest for cookie handling. Methods are short, focused, and mostly flat, with minimal nesting. Naming and comments clarify intent. Minor issues: the get_full_url method contains a multi-line list with a long cast expression, slightly reducing readability. The type annotation MockRequest.type is declared without initialization, relying on __init__, which is acceptable but not ideal. Some methods (e.g., get_new_headers) are trivial but add length. Overall, the logical organization and clear purpose make it quite readable, though not perfect.

Run 1

Code Structure: The class logically groups request-adapter methods, although import ordering is inconsistent and several imports are unused in this snippet. Nesting: Minimal nesting and an early return make control flow easy to follow. Clarity of intent: The class docstring, descriptive method names, and type annotations clearly explain its purpose; the abbreviated _r attribute and externally defined PreparedRequest slightly reduce local clarity. Code length: Mostly concise, though some wrapper methods and comments are repetitive. Action granularity: Statements generally perform one action per line; the nested dictionary lookups in get_header are slightly denser. Reading flow: Methods progress naturally from initialization through request information and header handling to properties, with consistent formatting overall. Minor distractions include redundant parentheses, a long type-ignore line, and a comment referring to a response when the class wraps a request.

Run 2

Code Structure: The class logically groups request-adapter methods and properties, though numerous unused imports and inconsistent import ordering add clutter. Nesting: Methods are flat, with only one simple conditional and an early return. Clarity of intent: The detailed class docstring, descriptive method names, and type annotations explain the adapter's purpose well; the abbreviated attribute `_r` and externally defined `PreparedRequest` annotation require additional context. Code length: Most methods are concise, but some comments repeat obvious operations and the imports unnecessarily lengthen the excerpt. Action granularity: Statements generally perform one action per line; the nested dictionary lookup in `get_header` is slightly denser. Reading flow: Initialization, interface methods, and property aliases follow a natural sequence, with minor distractions from redundant comments, a stray blank line, and the long return line.

Run 3

Code Structure: A cohesive adapter class groups related request-interface methods logically, although numerous unused imports and inconsistent import ordering add clutter. Nesting: Very shallow, with a simple conditional and early return. Clarity of intent: The class docstring, descriptive method names, and type annotations explain its purpose well; the abbreviated attribute `_r` and unexplained `PreparedRequest` reference slightly reduce clarity. Code length: Methods are concise, though some comments repeat obvious operations and imports are excessive for this snippet. Action granularity: Statements generally perform one action per line; the nested header lookup is compact but requires a little extra attention. Reading flow: Initialization followed by interface methods and properties creates a natural progression, with minor formatting inconsistencies and a long return line interrupting readability.