Sample

pyint-f26f9dd9cd5c-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines166

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.270–1; higher is more readable
Mi0.5610–1; higher is more readable
LLOC64Logical lines; fewer is more readable
DeepSeek V4 Pro160–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.3820–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.""" even_number_count = 0 for candidate_number in range(6): if candidate_number % 2 == 0: even_number_count += 1 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.4649.443−153.432
Source linesThe number of non-empty source lines.166+66.4
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.613−6.919

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.167−4.877
Indentation frequencyHow rapidly indentation changes from line to line.139+4.071
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.139−2.769
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.165.932+1.91
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.101.934+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.97−0.654
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.415

Intercept 0.07 + feature contributions = -0.994 (log-odds).
Score = sigmoid(-0.994) = 0.27.

Score0.561
Score64
Run 1

The code is well-structured with clear separation of imports, class definition, type annotations, and methods. Nesting is minimal, and the intent of the Request class is documented with a helpful docstring and usage example. Type hints improve clarity, and method signatures are explicit. However, the prepare method contains a useless loop that computes even_number_count but never uses it, which is ambiguous and hurts readability. Imports are extensive but organized logically. The code is concise overall, though the dead code in prepare() is unnecessarily confusing and should be removed. Action granularity is good, but the unexplained loop breaks reading flow.

Run 2

The code is highly readable overall. It has a clear structure with organized imports, type annotations, and a well-documented Request class. The __init__ method is flat and sequential, with each instance variable assignment on its own line, showing good action granularity. The docstring clearly explains the intent and usage. However, there is one notable issue: the prepare() method contains a pointless loop that computes even_number_count, which is never used. This confusing dead code hurts clarity of intent and reading flow. Additionally, the method signature is quite long, but this is mitigated by clean formatting. The code is concise despite many imports and generally follows the criteria well.

Run 3

The code is generally readable with clear structure and intent, but has some issues. Imports are logical but lengthy. The Request class has clear documentation and type hints, making its purpose evident. The __init__ method is straightforward with sensible default handling. The prepare() method contains an unexplained, irrelevant loop counting even numbers that doesn't contribute to the function's stated purpose, which obscures intent and adds unnecessary length. Variable naming is mostly clear. The class attributes and constructor parameters are well-typed, aiding readability. Action granularity is good - one logical operation per line. The reading flow is natural, moving from initialization to preparation. However, the presence of dead code (the counting loop) and the extensive import block reduce the score. The code would benefit from removing the unrelated loop and possibly grouping related imports more tightly. Overall, it's readable Python code with minor clarity issues, reflected in the moderate score.

Run 1

Code Structure: The class is logically organized into documentation, typed attributes, initialization, representation, and preparation, though the large import block and externally defined dependencies add overhead. Nesting: Most code is flat; the unnecessary counting loop introduces modest nesting. Clarity of intent: Descriptive names, type annotations, and detailed docstrings clearly explain request construction, but the unused even_number_count calculation has no apparent connection to preparation. Code length: Initialization and argument forwarding are straightforward, although imports, extensive documentation, and the irrelevant loop make this excerpt longer than necessary. Action granularity: Statements generally perform one action per line, and multiline signatures and calls are easy to scan. Reading flow: The progression from configuration to preparation is natural, but the unrelated counting logic interrupts it; the abbreviated variable p is also less informative than prepared_request.

Run 2

Code Structure: The class is logically organized into attributes, initialization, representation, and preparation, although many imports are unrelated to this excerpt. Nesting: Control flow is mostly flat, with only a shallow loop and conditional in prepare(). Clarity of intent: Descriptive names, type annotations, and comprehensive documentation clearly explain request construction. However, the unused even_number_count calculation is unrelated to preparing a request and distracts from its purpose; several referenced types and base classes are not defined in the excerpt. Code length: Most implementation is concise, but extensive imports and the redundant counting loop add clutter. Action granularity: Statements generally perform one action per line, and keyword arguments are neatly separated. Reading flow: Initialization followed by representation and preparation creates a natural progression, interrupted primarily by the irrelevant loop.

Run 3

Code Structure: The class is logically organized into documentation, attributes, initialization, representation, and preparation, though the extensive imports distract from the small implementation. Nesting: Mostly flat, with only shallow loops and conditionals. Clarity of intent: Descriptive names, type annotations, and detailed documentation clearly explain request construction; however, the unused even-number counting loop in prepare() is unrelated and confusing. Code length: Initialization and delegation are reasonably concise, but the irrelevant loop and large import section add unnecessary length to this excerpt. Action granularity: Statements generally perform one action per line, and multiline arguments are easy to scan. Reading flow: The progression from initialization to preparation is natural, but the counting loop interrupts it. Referenced classes and types not defined or imported in the excerpt also require external context.