Sample

pyint-a88552bc9b98-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines130

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.6260–1; higher is more readable
Mi0.4910–1; higher is more readable
LLOC60Logical lines; fewer is more readable
DeepSeek V4 Pro100–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.4440–1; higher is more readable

Views

Source code

from __future__ import annotations import datetime import encodings.idna # noqa: F401 from collections.abc import Callable, Generator, Iterable, Iterator, Mapping from io import UnsupportedOperation from typing import ( TYPE_CHECKING, Any, Final, Literal, cast, overload, ) from urllib3.exceptions import ( DecodeError, LocationParseError, ProtocolError, ReadTimeoutError, SSLError, ) from urllib3.fields import RequestField from urllib3.filepost import encode_multipart_formdata from urllib3.util import parse_url from . import _types as _t from ._internal_utils import to_native_string, unicode_is_ascii from .auth import HTTPBasicAuth from .compat import ( JSONDecodeError, basestring, builtin_str, chardet, cookielib, urlencode, urlsplit, urlunparse, ) from .compat import json as complexjson from .cookies import ( _copy_cookie_jar, cookiejar_from_dict, get_cookie_header, ) from .exceptions import ( ChunkedEncodingError, ConnectionError, ContentDecodingError, HTTPError, InvalidJSONError, InvalidURL, MissingSchema, StreamConsumedError, ) from .exceptions import JSONDecodeError as RequestsJSONDecodeError from .exceptions import SSLError as RequestsSSLError from .hooks import default_hooks from .status_codes import codes from .structures import CaseInsensitiveDict from .utils import ( check_header_validity, get_auth_from_url, guess_filename, guess_json_utf, iter_slices, parse_header_links, requote_uri, stream_decode_response_unicode, super_len, to_key_val_list, ) class Request(RequestHooksMixin): """A user-created :class:`Request <Request>` object. Used to prepare a :class:`PreparedRequest <PreparedRequest>`, which is sent to the server. :param method: HTTP method to use. :param url: URL to send. :param headers: dictionary of headers to send. :param files: dictionary of {filename: fileobject} files to multipart upload. :param data: the body to attach to the request. If a dictionary or list of tuples ``[(key, value)]`` is provided, form-encoding will take place. :param json: json for the body to attach to the request (if files or data is not specified). :param params: URL parameters to append to the URL. If a dictionary or list of tuples ``[(key, value)]`` is provided, form-encoding will take place. :param auth: Auth handler or (user, pass) tuple. :param cookies: dictionary or CookieJar of cookies to attach to this request. :param hooks: dictionary of callback hooks, for internal usage. Usage:: >>> import requests >>> req = requests.Request('GET', 'https://httpbin.org/get') >>> req.prepare() <PreparedRequest [GET]> """ hooks: dict[str, list[_t.HookType]] method: str | None url: _t.UriType | None headers: Mapping[str, str | bytes] files: _t.FilesType data: _t.DataType json: _t.JsonType params: _t.ParamsType auth: _t.AuthType cookies: RequestsCookieJar | CookieJar | dict[str, str] | None def __init__( self, method: str | None = None, url: _t.UriType | None = None, headers: _t.HeadersType = None, files: _t.FilesType = None, data: _t.DataType = None, params: _t.ParamsType = None, auth: _t.AuthType = None, cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None, hooks: _t.HooksInputType | None = None, json: _t.JsonType = None, ) -> None: # Default empty dicts for dict params. data = [] if data is None else data files = [] if files is None else files headers = {} if headers is None else headers params = {} if params is None else params hooks = {} if hooks is None else hooks self.hooks = default_hooks() for k, v in list(hooks.items()): self.register_hook(event=k, hook=v) self.method = method self.url = url self.headers = headers self.files = files self.data = data self.json = json self.params = params self.auth = auth self.cookies = cookies def __repr__(self) -> str: return f"<Request [{self.method}]>" def prepare(self) -> PreparedRequest: """Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it.""" p = PreparedRequest() p.prepare( method=self.method, url=self.url, headers=self.headers, files=self.files, data=self.data, json=self.json, params=self.params, auth=self.auth, cookies=self.cookies, hooks=self.hooks, ) return p

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.4437.184−146.427
Source linesThe number of non-empty source lines.130+52
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.599−6.898

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.131−3.602
Indentation frequencyHow rapidly indentation changes from line to line.105+2.895
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.149.969−2.687
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.149.985+1.615
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.129.861+1.405
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.419
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398

Intercept 0.07 + feature contributions = 0.514 (log-odds).
Score = sigmoid(0.514) = 0.626.

Score0.491
Score60
Run 1

The code shows mixed readability. While the class structure, type hints, and docstring demonstrate clear intent and good organization, the formatting severely impacts readability. Many import statements and the __init__ signature are unnecessarily broken across lines with awkward spacing, creating visual noise and disrupting natural reading flow. The __init__ method crams multiple parameters onto single lines despite available space, violating the 'one action per line' principle. Nesting is minimal and the logic is straightforward, but the inconsistent formatting patterns (e.g., mixed alignment in imports) make the code appear disorganized. The code length is reasonable, and the docstring is excellent, but the poor formatting choices significantly reduce clarity. With consistent formatting, this would score much higher.

Run 2

The code has logical organization but severely suffers from inconsistent and haphazard formatting, harming readability. Imports are grouped logically, but vertical alignment and spacing are erratic — some lines have excessive indentation or missing spaces around commas. Class structure is clear, but method signatures and function calls are broken into awkward, disorganized line wraps. Nesting is minimal, which is positive, and intent is generally clear thanks to docstrings and type hints. However, action granularity is uneven; some lines contain multiple statements while others are unnecessarily fragmented. Reading flow is disrupted by inconsistent line breaks and alignment, making the code feel messy. Overall, the structure is sound, but formatting inconsistencies drastically reduce readability.

Run 3

The code suffers from severe formatting inconsistencies that significantly impair readability. Import statements have erratic spacing and alignment (e.g., 'from typing import ( TYPE_CHECKING,') making them hard to scan. Function signatures and calls are broken across lines with excessive whitespace and misaligned parameters, disrupting visual flow. While the overall structure is logical and follows common request library patterns, the execution undermines clarity. The docstring is well-written and informative, but the surrounding code's garbled indentation and spacing overshadow this. Action granularity is mostly acceptable, with one main operation per line, but the chaotic alignment makes even simple assignments appear disorganized. Nesting is minimal, but the formatting issues create a perception of tangled code. The code is functional but would require substantial reformatting to meet professional readability standards.

Run 1

Code Structure: The class is logically organized into type declarations, initialization, representation, and preparation, although extensive imports obscure the main code. Nesting: Control flow is shallow, with only one straightforward loop. Clarity of intent: Descriptive names, type annotations, and documentation make the request object's purpose clear; dependencies not defined in the snippet require external context. Code length: The implementation is reasonably concise, but lengthy documentation and imports dominate this small excerpt. Action granularity: Most executable statements perform one action per line, while several imports, parameters, and keyword arguments are crowded onto shared lines. Reading flow: Methods follow a natural sequence, but inconsistent spacing, long signature lines, and limited separation between declarations and methods interrupt scanning.

Run 2

Code Structure: The class logically groups attributes, initialization, representation, and request preparation, although the extensive imports obscure its focus. Nesting: Shallow control flow makes execution easy to follow. Clarity of intent: Descriptive names, type annotations, and a detailed docstring clearly explain the class's purpose. Code length: Methods are concise, but many imports appear unused in this excerpt, adding visual overhead. Action granularity: Assignments generally perform one action per line; however, multiple parameters and keyword arguments crowded onto single lines hinder scanning. Reading flow: Initialization proceeds naturally from defaults to hooks to attribute assignment, followed by preparation. Inconsistent whitespace, poorly formatted signatures and imports, and limited spacing between sections interrupt that flow. Overall, the underlying logic is readable, but presentation significantly weakens readability.

Run 3

Code Structure: The class is logically organized into attributes, initialization, representation, and preparation, although the extensive import block distracts from the small implementation. Nesting: Control flow is shallow, with only a simple loop. Clarity of intent: Descriptive names, type annotations, and a detailed docstring clearly explain the request object's purpose. Code length: Methods are concise, but numerous imports unused in this excerpt and lengthy documentation add reading overhead. Action granularity: Assignments generally perform one action per line, but multiple parameters and keyword arguments crowded onto single lines reduce scanability. Reading flow: Initialization and preparation follow a natural sequence, but inconsistent spacing, awkward line wrapping, and limited separation between class sections interrupt the flow. Referenced types and the base class are not defined or imported in the excerpt, limiting standalone understanding.