Sample

pyint-1d1f60d9c3d2-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines162

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8930–1; higher is more readable
Mi0.5610–1; higher is more readable
LLOC60Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.4940–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.162+64.8
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.616−6.924

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.163−4.735
Indentation frequencyHow rapidly indentation changes from line to line.135+3.932
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.161.922+1.854
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.101.939+0.84
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.101.963−0.654
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.417
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398

Intercept 0.07 + feature contributions = 2.122 (log-odds).
Score = sigmoid(2.122) = 0.893.

Score0.561
Score60
Run 1

The code is highly readable with clear structure, minimal nesting, and explicit intent. Imports are logically grouped by source and alphabetized. The class has a clear docstring with examples, well-defined type hints, and defaults handled consistently. Each action in __init__ is concise, with one action per line, improving traceability. The prepare() method cleanly delegates to PreparedRequest. Minor deductions: the long import block adds vertical length, and some annotations (e.g., _t.UriType | None) slightly reduce readability for non-expert readers, but overall this is professional, maintainable code.

Run 2

The code is highly readable with clear logical organization, well-structured imports, and a straightforward class definition. The Request class has explicit type annotations, a comprehensive docstring with usage examples, and clear separation of concerns. The __init__ method uses a consistent pattern for default value handling with inline comments explaining the rationale. Nesting is minimal, with only one level in the hook registration loop. Each line performs a single action, maintaining good action granularity. The reading flow is natural, moving from class documentation to type declarations, then initialization logic, and finally methods. The code is concise without sacrificing clarity, avoiding unnecessary verbosity. Minor deductions: the import section is lengthy, though properly organized, and some type aliases like _t.UriType require checking the types module for full comprehension, slightly impacting immediate readability for newcomers.

Run 3

The code is highly readable due to its clear structure and organization. The imports are logically grouped, making dependencies easy to understand. The Request class has a well-documented docstring with clear parameter descriptions and usage examples. Type hints are used extensively, improving clarity and maintainability. The __init__ method handles default values concisely with conditional assignments. The nesting is flat, with no deeply nested logic. Each action has its own line, such as setting attributes or registering hooks. The reading flow is natural, progressing from imports to class definition, attributes, methods, and finally the prepare method. Minor deductions: the class depends on RequestHooksMixin and PreparedRequest which are not shown, slightly reducing standalone clarity. The default value assignments could be marginally simplified with a helper, but are acceptable. Overall, the code is clean, well-documented, and easy to follow.

Run 1

Code Structure: The class is logically organized into documentation, attribute declarations, initialization, representation, and preparation; however, many imports are unused in this excerpt, and referenced types and base classes are not defined here. Nesting: Control flow is shallow, with only one simple loop. Clarity of intent: Descriptive names, type annotations, and a usage example clearly explain request construction and preparation, though the variable names p, k, and v are less expressive. Code length: The implementation is concise, but extensive imports and documentation make the excerpt longer than its functionality requires. Action granularity: Statements generally perform one action per line, and multiline calls clearly separate arguments. Reading flow: Methods follow a natural lifecycle, and formatting is consistent; the large import block and external dependencies slightly interrupt otherwise straightforward reading.

Run 2

Code Structure: The class is logically organized into documentation, attribute declarations, initialization, representation, and preparation, although the extensive import block includes many names unused in this snippet. Nesting: Control flow is almost entirely flat, with only a simple hook-registration loop. Clarity of intent: Descriptive names, type annotations, and detailed documentation clearly communicate the request object's purpose; externally defined types and base classes require additional context. Code length: Methods are concise, but lengthy imports, documentation, and repeated field declarations and assignments add reading overhead. Action granularity: Statements generally perform one action per line, making initialization and delegation easy to inspect. Reading flow: Defaults, hook setup, field assignments, and preparation follow a natural sequence. Minor distractions include the generic variable name 'p' and a comment describing default dictionaries when data and files actually default to lists.

Run 3

Code Structure: The class is logically organized into documentation, attribute declarations, initialization, representation, and preparation, although the extensive imports distract from this small excerpt. Nesting: Control flow is flat, with only a simple loop. Clarity of intent: Descriptive method names, type annotations, parameter documentation, and a usage example clearly explain the request object's purpose. Some referenced types and the base class are not defined or imported in the excerpt, reducing standalone clarity. Code length: The implementation is concise, but lengthy documentation, imports, and repeated parameter lists add reading overhead. Action granularity: Statements generally perform one action per line, and multiline calls are easy to scan. Reading flow: Defaults, hook setup, attribute assignment, and preparation follow a natural sequence. Minor issues include abbreviated local names such as p, k, and v, and a comment describing empty dictionaries when some defaults are lists.