Sample

pyint-76c4345259ca-I01

Remove comments and docstrings

Matched original source

Lines299

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.040–1; higher is more readable
Mi0.640–1; higher is more readable
LLOC129Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.4290–1; higher is more readable

Views

Source code

from __future__ import annotations import os import sys import time from collections import OrderedDict from collections.abc import Generator, Mapping, MutableMapping from datetime import timedelta from typing import TYPE_CHECKING, Any, cast from ._internal_utils import to_native_string from ._types import is_prepared as _is_prepared from .adapters import HTTPAdapter from .auth import _basic_auth_str from .compat import cookielib, urljoin, urlparse from .cookies import ( RequestsCookieJar, cookiejar_from_dict, extract_cookies_to_jar, merge_cookies, ) from .exceptions import ( ChunkedEncodingError, ContentDecodingError, InvalidSchema, TooManyRedirects, ) from .hooks import default_hooks, dispatch_hook from .models import ( DEFAULT_REDIRECT_LIMIT, REDIRECT_STATI, PreparedRequest, Request, Response, ) from .status_codes import codes from .structures import CaseInsensitiveDict from .utils import ( DEFAULT_PORTS, default_headers, get_auth_from_url, get_environ_proxies, get_netrc_auth, requote_uri, resolve_proxies, rewind_body, should_bypass_proxies, to_key_val_list, ) class SessionRedirectMixin: max_redirects: int trust_env: bool cookies: RequestsCookieJar def send(self, request: PreparedRequest, **kwargs: Any) -> Response: ... def get_redirect_target(self, resp: Response) -> str | None: if resp.is_redirect: location = resp.headers["location"] location = location.encode("latin1") return to_native_string(location, "utf8") return None def should_strip_auth(self, old_url: str, new_url: str) -> bool: old_parsed = urlparse(old_url) new_parsed = urlparse(new_url) if old_parsed.hostname != new_parsed.hostname: return True if ( old_parsed.scheme == "http" and old_parsed.port in (80, None) and new_parsed.scheme == "https" and new_parsed.port in (443, None) ): return False changed_port = old_parsed.port != new_parsed.port changed_scheme = old_parsed.scheme != new_parsed.scheme default_port = (DEFAULT_PORTS.get(old_parsed.scheme, None), None) if ( not changed_scheme and old_parsed.port in default_port and new_parsed.port in default_port ): return False return changed_port or changed_scheme def resolve_redirects( self, resp: Response, req: PreparedRequest, stream: bool = False, timeout: _t.TimeoutType = None, verify: _t.VerifyType = True, cert: _t.CertType = None, proxies: dict[str, str] | None = None, yield_requests: bool = False, **adapter_kwargs: Any, ) -> Generator[Response, None, None]: hist: list[Response] = [] url = self.get_redirect_target(resp) previous_fragment = urlparse(req.url).fragment while url: prepared_request = req.copy() resp.history = hist[:] hist.append(resp) try: resp.content except (ChunkedEncodingError, ContentDecodingError, RuntimeError): resp.raw.read(decode_content=False) if len(resp.history) >= self.max_redirects: raise TooManyRedirects( f"Exceeded {self.max_redirects} redirects.", response=resp ) resp.close() if url.startswith("//"): parsed_rurl = urlparse(resp.url) url = ":".join([to_native_string(parsed_rurl.scheme), url]) parsed = urlparse(url) if parsed.fragment == "" and previous_fragment: parsed = parsed._replace(fragment=previous_fragment) elif parsed.fragment: previous_fragment = parsed.fragment url = parsed.geturl() if not parsed.netloc: url = urljoin(resp.url, requote_uri(url)) else: url = requote_uri(url) prepared_request.url = to_native_string(url) self.rebuild_method(prepared_request, resp) if resp.status_code not in ( codes.temporary_redirect, codes.permanent_redirect, ): purged_headers = ("Content-Length", "Content-Type", "Transfer-Encoding") for header in purged_headers: prepared_request.headers.pop(header, None) prepared_request.body = None headers = prepared_request.headers headers.pop("Cookie", None) cookie_jar = cast("CookieJar", prepared_request._cookies) extract_cookies_to_jar(cookie_jar, req, resp.raw) merge_cookies(cookie_jar, self.cookies) prepared_request.prepare_cookies(cookie_jar) proxies = self.rebuild_proxies(prepared_request, proxies) self.rebuild_auth(prepared_request, resp) rewindable = prepared_request._body_position is not None and ( "Content-Length" in headers or "Transfer-Encoding" in headers ) if rewindable: rewind_body(prepared_request) req = prepared_request if yield_requests: yield req else: resp = self.send( req, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies, allow_redirects=False, **adapter_kwargs, ) extract_cookies_to_jar(self.cookies, prepared_request, resp.raw) url = self.get_redirect_target(resp) yield resp def rebuild_auth( self, prepared_request: PreparedRequest, response: Response ) -> None: original_request = response.request assert _is_prepared(original_request) assert _is_prepared(prepared_request) headers = prepared_request.headers original_url = original_request.url url = prepared_request.url if "Authorization" in headers and self.should_strip_auth(original_url, url): del headers["Authorization"] new_auth = get_netrc_auth(url) if self.trust_env else None if new_auth is not None: prepared_request.prepare_auth(new_auth) def rebuild_proxies( self, prepared_request: PreparedRequest, proxies: dict[str, str] | None, ) -> dict[str, str]: assert _is_prepared(prepared_request) headers = prepared_request.headers scheme = urlparse(prepared_request.url).scheme new_proxies = resolve_proxies(prepared_request, proxies, self.trust_env) if "Proxy-Authorization" in headers: del headers["Proxy-Authorization"] try: username, password = get_auth_from_url(new_proxies[scheme]) except KeyError: username, password = None, None if not scheme.startswith("https") and username and password: headers["Proxy-Authorization"] = _basic_auth_str(username, password) return new_proxies def rebuild_method( self, prepared_request: PreparedRequest, response: Response ) -> None: method = prepared_request.method if response.status_code == codes.see_other and method != "HEAD": method = "GET" if response.status_code == codes.found and method != "HEAD": method = "GET" if response.status_code == codes.moved and method == "POST": method = "GET" prepared_request.method = method

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.8909.906−294.027
Source linesThe number of non-empty source lines.299+119.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.166−6.25

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.299+9.605
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.300−9.586
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.299−6.44
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.298.91+3.768
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.069+0.269
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.957−0.06

Intercept 0.07 + feature contributions = -3.178 (log-odds).
Score = sigmoid(-3.178) = 0.04.

Score0.64
Score129
Run 1

The code demonstrates generally good structure with logical organization into focused methods, mostly flat nesting, and clear intent through descriptive method names. However, several issues impact readability: excessive blank lines with empty comment placeholders (removed documentation strings) disrupt flow, type hints reference undefined '_t' namespace, and long methods like 'resolve_redirects' pack many operations together. While individual operations are well-separated, the redirect loop's complexity is somewhat hidden by inline comments that substitute for proper documentation. The mixed use of single-letter variables ('req', 'resp') versus descriptive names creates inconsistency. Action granularity is appropriate with one operation per line, and reading flow follows a natural sequence, but the missing docstrings and scattered empty comments suggest incomplete documentation that would otherwise clarify intent. The code would benefit from extracting the redirect loop body into helper methods and restoring proper docstrings.

Run 2

The code has clear intent and logical structure, but suffers from readability issues. Many lines appear as blank or whitespace-only, especially in get_redirect_target and should_strip_auth, which disrupts the reading flow. There are excessive trailing spaces after lines like `hist: list[Response] = [] ` and `yield req `, suggesting missing comments or accidental formatting. Nesting is mostly flat, which is good, and action granularity is reasonable. However, some methods (resolve_redirects) are long and carry many responsibilities, making them harder to follow. Type hints and descriptive method names help clarity, but the incomplete or absent comments where whitespace remains indicate unclear documentation. The import block is clean, but the overall formatting inconsistency lowers readability.

Run 3

The code is generally well-structured with clear method separation and logical organization. Most methods have single responsibility and use descriptive names. The nesting depth is moderate but acceptable. Comments explain non-obvious logic, particularly around redirect handling and auth stripping. However, there are several issues: excessive blank lines with placeholder comments (e.g., 11 consecutive empty comment lines in get_redirect_target), inconsistent whitespace in imports and type hints (_t.TimeoutType, _t.VerifyType, _t.CertType are undefined - likely missing import), and some long methods like resolve_redirects that handle many concerns. The reading flow is mostly natural but the method could benefit from extracting helper functions. Minor inconsistency exists with inline comments and spacing. Overall, the code follows Python conventions well and maintains reasonable clarity despite some complexity inherent to redirect handling.

Run 1

Code Structure: Related redirect operations are organized into a coherent mixin with focused helper methods, although resolve_redirects handles many responsibilities. Nesting: Generally moderate, with straightforward conditionals; the redirect loop contains several nested branches but remains manageable. Clarity of intent: Descriptive method names, variables, and type annotations communicate purpose, but undocumented HTTP edge cases, abbreviated names, and unresolved annotation references such as _t reduce clarity. Code length: Mostly justified by redirect complexity, but excessive blank lines, unused imports, and the lengthy central method add unnecessary bulk. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: Redirect processing follows a logical sequence, but large whitespace gaps and missing explanatory comments interrupt continuity and obscure why certain transformations are necessary.

Run 2

Code Structure: The mixin groups related redirect behavior logically, with focused helpers, but resolve_redirects combines many responsibilities. Nesting: Mostly shallow conditionals and early returns; the redirect loop adds moderate nesting without becoming tangled. Clarity of intent: Descriptive method names and type annotations help, but undocumented HTTP edge cases, missing context for _t and CookieJar, and inconsistent generator annotations obscure details. Code length: Helpers are reasonably concise, while resolve_redirects is long and excessive blank lines inflate the presentation. Action granularity: Statements generally perform one action per line, making changes easy to track. Reading flow: Redirect processing follows a coherent sequence, but whitespace gaps and the absence of explanatory comments interrupt reading and leave subtle encoding, authentication, and body-rewinding decisions unexplained.

Run 3

Code Structure: The redirect mixin is logically organized into focused helpers, although resolve_redirects combines many responsibilities. Nesting: Mostly shallow conditionals and early returns; the redirect loop adds moderate nesting without becoming tangled. Clarity of intent: Descriptive method and variable names convey purpose, but missing explanatory comments obscure HTTP edge cases, and unresolved type names such as _t and CookieJar distract readers. Code length: Most helpers are concise, but resolve_redirects is lengthy and excessive blank lines unnecessarily expand the code. Action granularity: Statements generally perform one action per line, making individual operations easy to follow. Reading flow: Redirect processing follows a coherent sequence, supported by helper methods, but irregular whitespace, unused imports, and undocumented state changes interrupt the flow.