Sample

pyint-f91f026097f3-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines93

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4050–1; higher is more readable
Mi0.4590–1; higher is more readable
LLOC50Logical lines; fewer is more readable
DeepSeek V4 Pro7.330–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.5510–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, req: PreparedRequest) -> None: assert _is_prepared(req) self._r = req self._new_headers: dict[str, str] = {} self.type = urlparse(self._r.url).scheme def get2(self) -> str: return self.type def get3(self) -> str: return urlparse(self._r.url).netloc def get4(self) -> str: return self.get3() def get5(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 hos2 = to_native_string(self._r.headers["Host"], encoding="utf-8") par = urlparse(self._r.url) # Reconstruct the URL as we expect it return urlunparse( [ par.scheme, hos2, par.path, par.params, par.query, par.fragment, ] ) def is2(self) -> bool: return True def has(self, nam: str) -> bool: return nam in self._r.headers or nam in self._new_headers def get6(self, nam2: str, def2: str | None = None) -> str | None: return self._r.headers.get(nam2, self._new_headers.get(nam2, def2)) # type: ignore[return-value] def add(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 add2(self, nam3: str, val2: str) -> None: self._new_headers[nam3] = val2 def get7(self) -> dict[str, str]: return self._new_headers @property def unv(self) -> bool: return self.is2() @property def origin(self) -> str: return self.get4() @property def hos(self) -> str: return self.get3()

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.2946.021−97.219
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.52−6.78

Intercept 8.87 + feature contributions = -57.928 (log-odds).
Score = sigmoid(-57.928) = 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
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.92.849+0.888
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.103.872+0.871
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.104.947−0.78
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.071+0.256

Intercept 0.07 + feature contributions = -0.383 (log-odds).
Score = sigmoid(-0.383) = 0.405.

Score0.459
Score50
Run 1

The code has a clear conceptual purpose (wrapping a requests object for cookiejar compatibility) but suffers from poor naming and structure. Methods like `get2`, `get3`, `get4`, `get5`, `get6`, `get7`, `add2`, `has`, `is2`, `unv`, `hos` are largely meaningless and obscure intent, forcing readers to infer function by implementation. Naming such as `nam`, `def2`, `hos2`, `nam2` reduces clarity further. While nesting is low and lines are generally concise, the reading flow is disjointed because method names do not reflect their actions. The class is not excessively long, but duplicated logic (e.g., repeated `urlparse`) and unclear abstractions reduce readability. Action granularity is mostly one action per line. Overall, the structure is coherent but the lack of descriptive identifiers significantly hampers understanding.

Run 2

The code suffers from severe readability issues. Method names like 'get2', 'get3', 'add2', 'is2', 'has', etc. are completely opaque and provide no indication of their purpose. The class docstring is helpful, but the methods themselves obscure intent. The code uses multiple aliases (e.g., 'get3' vs 'get4') and the parameter names ('nam', 'nam2', 'nam3', 'def2', 'val2', 'hos2') are meaningless. The logic in 'get5' is convoluted for reconstructing a URL. The structure is somewhat flat and logical, and actions are mostly one per line, but the terrible naming undermines clarity of intent and reading flow. The code is not excessively long, but the cryptic naming makes it effectively unreadable. The use of TYPE_CHECKING, typing, and internal imports is fine, but the method names make it impossible to understand what the code does without significant investigation.

Run 3

This code is significantly unreadable due to obfuscated method names (get2, get3, get4, get5, get6, get7, add2), vague parameter names (nam, nam2, nam3, def2, val2), and meaningless type hints. The class structure is present but undermined by unclear intent throughout. While there is minimal nesting and action granularity is acceptable, the reading flow is severely disrupted by cryptic naming. Code length is concise for what it does, but clarity of intent is almost entirely absent. The original functionality (mocking a request for cookiejar) is hard to discern without significant effort. The imports are excessive and unused ones appear, further clouding intent. Overall, the logic is recognizable but the naming choices render it nearly unreadable.

Run 1

Code Structure: A single wrapper class groups related behavior logically, but unused imports and inconsistent import ordering add clutter. Nesting: Methods are flat, with only one simple conditional, making control flow easy to follow. Clarity of intent: The class docstring and URL-reconstruction comments help, but names such as get2, get5, hos2, nam2, and unv obscure method purposes and data meanings. Code length: Most methods are concise, although trivial forwarding methods and unused imports introduce overhead. Action granularity: Statements generally perform one action per line; the nested header lookup is slightly denser but still manageable. Reading flow: Initialization, accessors, and header operations form a reasonably natural sequence, but cryptic naming and documentation references to methods not present under those names interrupt comprehension.

Run 2

Code Structure: A single, logically organized wrapper class separates initialization, request access, and header handling, though import ordering is inconsistent. Nesting: Very shallow; the conditional in get5 is easy to follow. Clarity of intent: The class docstring, comments, and type annotations provide useful context, but names such as get2 through get7, is2, hos2, nam2, and unv obscure method purposes and relationships. Code length: Generally concise, although several imports are unused in this snippet and trivial forwarding methods add some overhead. Action granularity: Statements generally perform one action per line; the nested dictionary lookup in get6 is slightly denser. Reading flow: Consistent formatting and short methods help navigation, but opaque naming forces readers to inspect implementations repeatedly, and properties placed at the end require tracing back to ambiguously named methods.

Run 3

Code Structure: The wrapper is logically organized into small methods and properties, though imports are inconsistently grouped and several appear unused. Nesting: Almost entirely flat, with one simple conditional, making control flow easy to follow. Clarity of intent: The class docstring and URL-reconstruction comments explain the overall purpose, but names such as get2–get7, is2, nam2, hos2, and par obscure individual responsibilities. Comments and error messages also reference descriptive methods absent under those names, increasing confusion. Code length: Generally concise, although trivial forwarding methods and properties introduce some indirection. Action granularity: Statements typically perform one action per line; the nested header lookup is slightly denser but manageable. Reading flow: Formatting, type annotations, and short methods support scanning, but deciphering numbered names and following aliases interrupts an otherwise natural flow.